cache

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKey

func GenerateKey(method, url string, headers map[string]string) string

GenerateKey generates a cache key from request parameters

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provides a thread-safe LRU cache for HTTP responses

func New

func New(config *Config) *Cache

New creates a new cache

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all entries from the cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes an entry from the cache

func (*Cache) Get

func (c *Cache) Get(key string) (*Entry, bool)

Get retrieves a cached entry

func (*Cache) GetStats

func (c *Cache) GetStats() Stats

GetStats returns current cache statistics

func (*Cache) Set

func (c *Cache) Set(key string, value []byte, headers map[string][]string, statusCode int, ttl time.Duration) error

Set stores an entry in the cache

type Config

type Config struct {
	MaxSize int64         // Maximum cache size in bytes
	MaxAge  time.Duration // Maximum age of cached entries
}

Config defines cache configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default cache configuration

type Entry

type Entry struct {
	Key        string
	Value      []byte
	Headers    map[string][]string
	StatusCode int
	ExpiresAt  int64 // Unix timestamp in nanoseconds
	CreatedAt  int64
	AccessedAt int64
	HitCount   int64
}

Entry represents a cached response

type Stats

type Stats struct {
	Entries     int64
	Size        int64
	MaxSize     int64
	HitRate     float64
	TotalHits   int64
	TotalMisses int64
}

Stats returns cache statistics

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL