Documentation ¶
Index ¶
- func NewNoopCache[K comparable, V any]() *noopCache[K, V]
- type Cache
- type CacheWithEviction
- func NewLFUWithEviction[K comparable, V any](reg prometheus.Registerer, maxEntries int, onEvictedCallback func(k K, v V)) (*CacheWithEviction[K, V], error)
- func NewLRUWithEviction[K comparable, V any](reg prometheus.Registerer, maxEntries int, onEvictedCallback func(k K, v V)) (*CacheWithEviction[K, V], error)
- type CacheWithEvictionTTL
- func (c *CacheWithEvictionTTL[K, V]) Add(key K, value V)
- func (c *CacheWithEvictionTTL[K, V]) Close() error
- func (c *CacheWithEvictionTTL[K, V]) Get(key K) (V, bool)
- func (c *CacheWithEvictionTTL[K, V]) Peek(key K) (V, bool)
- func (c *CacheWithEvictionTTL[K, V]) Purge()
- func (c *CacheWithEvictionTTL[K, V]) Remove(key K)
- type CacheWithTTL
- type CacheWithTTLOptions
- type LoaderFunc
- type LoadingLRUCacheWithTTL
- type LoadingOnceCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewNoopCache ¶ added in v0.20.0
func NewNoopCache[K comparable, V any]() *noopCache[K, V]
Types ¶
type Cache ¶ added in v0.27.0
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
func NewLFUCache ¶ added in v0.27.0
func NewLFUCache[K comparable, V any](reg prometheus.Registerer, maxEntries int) *Cache[K, V]
NewLFUCache returns a new concurrency-safe fixed size cache with LFU exiction policy.
func NewLRUCache ¶ added in v0.20.0
func NewLRUCache[K comparable, V any](reg prometheus.Registerer, maxEntries int) *Cache[K, V]
NewLRUCache returns a new concurrency-safe fixed size cache with LRU exiction policy.
type CacheWithEviction ¶ added in v0.27.0
type CacheWithEviction[K comparable, V any] struct { // contains filtered or unexported fields }
func NewLFUWithEviction ¶ added in v0.27.0
func NewLFUWithEviction[K comparable, V any](reg prometheus.Registerer, maxEntries int, onEvictedCallback func(k K, v V)) (*CacheWithEviction[K, V], error)
NewLFUWithEviction returns a new LFU cache with a given maximum size and eviction callback.
func NewLRUWithEviction ¶ added in v0.20.0
func NewLRUWithEviction[K comparable, V any](reg prometheus.Registerer, maxEntries int, onEvictedCallback func(k K, v V)) (*CacheWithEviction[K, V], error)
NewLRUWithEviction returns a new LRU cache with a given maximum size and eviction callback.
func (*CacheWithEviction[K, V]) Add ¶ added in v0.27.0
func (c *CacheWithEviction[K, V]) Add(key K, value V)
Add adds a value to the cache.
func (*CacheWithEviction[K, V]) Close ¶ added in v0.27.0
func (c *CacheWithEviction[K, V]) Close()
Close is used to close the underlying LRU by also purging it.
func (*CacheWithEviction[K, V]) Get ¶ added in v0.27.0
func (c *CacheWithEviction[K, V]) Get(key K) (V, bool)
Get looks up a key's value from the cache.
func (*CacheWithEviction[K, V]) Peek ¶ added in v0.27.0
func (c *CacheWithEviction[K, V]) Peek(key K) (V, bool)
Peek returns the value associated with key without updating the "recently used"-ness of that key.
func (*CacheWithEviction[K, V]) Purge ¶ added in v0.27.0
func (c *CacheWithEviction[K, V]) Purge()
Purge is used to completely clear the cache.
func (*CacheWithEviction[K, V]) Remove ¶ added in v0.27.0
func (c *CacheWithEviction[K, V]) Remove(key K)
Remove removes the provided key from the cache.
type CacheWithEvictionTTL ¶ added in v0.27.0
type CacheWithEvictionTTL[K comparable, V any] struct { // contains filtered or unexported fields }
func NewLFUCacheWithEvictionTTL ¶ added in v0.27.0
func NewLFUCacheWithEvictionTTL[K comparable, V any](reg prometheus.Registerer, maxEntries int, ttl time.Duration, onEvictedCallback func(k K, v V)) *CacheWithEvictionTTL[K, V]
NewLFUCacheWithEvictionTTL returns a new concurrency-safe fixed size cache with LFU exiction policy, TTL and eviction callback.
func NewLRUCacheWithEvictionTTL ¶ added in v0.20.0
func NewLRUCacheWithEvictionTTL[K comparable, V any](reg prometheus.Registerer, maxEntries int, ttl time.Duration, onEvictedCallback func(k K, v V)) *CacheWithEvictionTTL[K, V]
NewLRUCacheWithEvictionTTL returns a new concurrency-safe fixed size cache with LRU exiction policy, TTL and eviction callback.
func (*CacheWithEvictionTTL[K, V]) Add ¶ added in v0.27.0
func (c *CacheWithEvictionTTL[K, V]) Add(key K, value V)
func (*CacheWithEvictionTTL[K, V]) Close ¶ added in v0.27.0
func (c *CacheWithEvictionTTL[K, V]) Close() error
func (*CacheWithEvictionTTL[K, V]) Get ¶ added in v0.27.0
func (c *CacheWithEvictionTTL[K, V]) Get(key K) (V, bool)
func (*CacheWithEvictionTTL[K, V]) Peek ¶ added in v0.27.0
func (c *CacheWithEvictionTTL[K, V]) Peek(key K) (V, bool)
func (*CacheWithEvictionTTL[K, V]) Purge ¶ added in v0.27.0
func (c *CacheWithEvictionTTL[K, V]) Purge()
func (*CacheWithEvictionTTL[K, V]) Remove ¶ added in v0.27.0
func (c *CacheWithEvictionTTL[K, V]) Remove(key K)
type CacheWithTTL ¶ added in v0.27.0
type CacheWithTTL[K comparable, V any] struct { // contains filtered or unexported fields }
func NewLFUCacheWithTTL ¶ added in v0.27.0
func NewLFUCacheWithTTL[K comparable, V any](reg prometheus.Registerer, maxEntries int, ttl time.Duration, opts ...CacheWithTTLOptions) *CacheWithTTL[K, V]
NewLFUCacheWithTTL returns a new concurrency-safe fixed size cache with LFU exiction policy and TTL.
func NewLRUCacheWithTTL ¶ added in v0.20.0
func NewLRUCacheWithTTL[K comparable, V any](reg prometheus.Registerer, maxEntries int, ttl time.Duration, opts ...CacheWithTTLOptions) *CacheWithTTL[K, V]
NewLRUCache returns a new concurrency-safe fixed size cache with LRU exiction policy and TTL.
func (*CacheWithTTL[K, V]) Add ¶ added in v0.27.0
func (c *CacheWithTTL[K, V]) Add(key K, value V)
func (*CacheWithTTL[K, V]) Close ¶ added in v0.27.0
func (c *CacheWithTTL[K, V]) Close() error
func (*CacheWithTTL[K, V]) Get ¶ added in v0.27.0
func (c *CacheWithTTL[K, V]) Get(key K) (V, bool)
func (*CacheWithTTL[K, V]) Peek ¶ added in v0.27.0
func (c *CacheWithTTL[K, V]) Peek(key K) (V, bool)
func (*CacheWithTTL[K, V]) Purge ¶ added in v0.27.0
func (c *CacheWithTTL[K, V]) Purge()
func (*CacheWithTTL[K, V]) Remove ¶ added in v0.27.0
func (c *CacheWithTTL[K, V]) Remove(key K)
type CacheWithTTLOptions ¶ added in v0.20.0
type LoaderFunc ¶ added in v0.20.0
type LoaderFunc[K comparable, V any] func(K) (V, error)
type LoadingLRUCacheWithTTL ¶ added in v0.20.0
type LoadingLRUCacheWithTTL[K comparable, V any] struct { // contains filtered or unexported fields }
func NewLoadingLRUCacheWithTTL ¶ added in v0.20.0
func NewLoadingLRUCacheWithTTL[K comparable, V any](reg prometheus.Registerer, maxEntries int, ttl time.Duration, loader LoaderFunc[K, V]) *LoadingLRUCacheWithTTL[K, V]
func (*LoadingLRUCacheWithTTL[K, V]) Close ¶ added in v0.20.0
func (c *LoadingLRUCacheWithTTL[K, V]) Close() error
func (*LoadingLRUCacheWithTTL[K, V]) Get ¶ added in v0.20.0
func (c *LoadingLRUCacheWithTTL[K, V]) Get(key K) (V, error)
type LoadingOnceCache ¶ added in v0.24.0
type LoadingOnceCache[K comparable, V any] struct { *LoadingLRUCacheWithTTL[K, V] // contains filtered or unexported fields }
func NewLoadingOnceCache ¶ added in v0.20.0
func NewLoadingOnceCache[K comparable, V any](reg prometheus.Registerer, maxEntries int, ttl time.Duration, loader LoaderFunc[K, V]) *LoadingOnceCache[K, V]
NewLoadingOnceCache creates a LoadingCache that allows only one loading operation at a time.
The returned LoadingCache will call the loader function to load entries on cache misses. However, it will use a singleflight.Group to ensure only one concurrent call to the loader is made for a given key. This can be used to prevent redundant loading of data on cache misses when multiple concurrent requests are made for the same key.
func (*LoadingOnceCache[K, V]) Get ¶ added in v0.24.0
func (c *LoadingOnceCache[K, V]) Get(key K) (V, error)