Documentation ¶
Index ¶
- Constants
- type Cache
- type CacheConfig
- type CacheEntry
- type CacheMetrics
- type CacheOption
- func WithCacheFailures(cacheFailures bool) CacheOption
- func WithCacheFilters(cacheFilters []string) CacheOption
- func WithEvictionPolicy(evictionPolicy string) CacheOption
- func WithEvictionTimer(evictionTimer time.Duration) CacheOption
- func WithLogger(l *log.Logger) CacheOption
- func WithMaxMemory(maxMemory uint64) CacheOption
- func WithMaxSize(maxSize int) CacheOption
- func WithMaxTTL(maxTtl time.Duration) CacheOption
- func WithTTL(ttl time.Duration) CacheOption
- type CacheResponse
- type EvictionPolicy
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { *sync.Mutex // Mutex for synchronizing access to the cache CacheConfig // Cache configuration options // contains filtered or unexported fields }
Cache stores the cache configuration and data
func NewCache ¶
func NewCache(options ...CacheOption) *Cache
NewCache initializes a new instance of Cache with given options
func (*Cache) Metrics ¶
func (c *Cache) Metrics() *CacheMetrics
func (*Cache) Middleware ¶
Middleware function to intercept all HTTP requests on a handler.
func (*Cache) MiddlewareFunc ¶
func (c *Cache) MiddlewareFunc(next http.HandlerFunc) http.HandlerFunc
Middleware function to intercept HTTP requests to a given route
type CacheConfig ¶ added in v1.0.1
type CacheConfig struct {
// contains filtered or unexported fields
}
CacheConfig stores the configuration options for the cache All of these options can be set using CacheOption functions
type CacheEntry ¶
type CacheEntry struct {
// contains filtered or unexported fields
}
CacheEntry stores a single cache item
type CacheMetrics ¶
CacheMetrics stores the cache metrics
type CacheOption ¶
type CacheOption func(*Cache)
func WithCacheFailures ¶ added in v1.0.1
func WithCacheFailures(cacheFailures bool) CacheOption
Set whether to cache failed requests
func WithCacheFilters ¶
func WithCacheFilters(cacheFilters []string) CacheOption
Set the cache filters to use for generating cache keys
func WithEvictionPolicy ¶
func WithEvictionPolicy(evictionPolicy string) CacheOption
Set the eviction policy for the cache [FIFO, LRU]
func WithEvictionTimer ¶
func WithEvictionTimer(evictionTimer time.Duration) CacheOption
Set the time between cache eviction checks
func WithLogger ¶
func WithLogger(l *log.Logger) CacheOption
Set the logger to use for cache logging
func WithMaxMemory ¶
func WithMaxMemory(maxMemory uint64) CacheOption
Set the maximum memory usage of the cache
func WithMaxSize ¶
func WithMaxSize(maxSize int) CacheOption
Set the maximum number of entries in the cache
func WithMaxTTL ¶
func WithMaxTTL(maxTtl time.Duration) CacheOption
Set the maximum time a cache entry can live, including renewals
func WithTTL ¶
func WithTTL(ttl time.Duration) CacheOption
Set the time a cache entry can live without being accessed
type CacheResponse ¶
CacheResponse stores the response info to be cached
type EvictionPolicy ¶
type EvictionPolicy string
const ( LRU EvictionPolicy = "LRU" FIFO EvictionPolicy = "FIFO" )