Documentation
¶
Index ¶
- func NewNoopCache[K comparable, V any]() *noopCache[K, V]
- type CacheWithTTLOptions
- type LRUCache
- type LRUCacheWithEvictionTTL
- func (c *LRUCacheWithEvictionTTL[K, V]) Add(key K, value V)
- func (c *LRUCacheWithEvictionTTL[K, V]) Close() error
- func (c *LRUCacheWithEvictionTTL[K, V]) Get(key K) (V, bool)
- func (c *LRUCacheWithEvictionTTL[K, V]) Peek(key K) (V, bool)
- func (c *LRUCacheWithEvictionTTL[K, V]) Purge()
- func (c *LRUCacheWithEvictionTTL[K, V]) Remove(key K)
- type LRUCacheWithTTL
- type LRUWithEviction
- 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 CacheWithTTLOptions ¶ added in v0.20.0
type LRUCache ¶ added in v0.20.0
type LRUCache[K comparable, V any] struct { // contains filtered or unexported fields }
func NewLRUCache ¶ added in v0.20.0
func NewLRUCache[K comparable, V any](reg prometheus.Registerer, maxEntries int) *LRUCache[K, V]
type LRUCacheWithEvictionTTL ¶ added in v0.20.0
type LRUCacheWithEvictionTTL[K comparable, V any] struct { // contains filtered or unexported fields }
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)) *LRUCacheWithEvictionTTL[K, V]
func (*LRUCacheWithEvictionTTL[K, V]) Add ¶ added in v0.20.0
func (c *LRUCacheWithEvictionTTL[K, V]) Add(key K, value V)
func (*LRUCacheWithEvictionTTL[K, V]) Close ¶ added in v0.20.0
func (c *LRUCacheWithEvictionTTL[K, V]) Close() error
func (*LRUCacheWithEvictionTTL[K, V]) Get ¶ added in v0.20.0
func (c *LRUCacheWithEvictionTTL[K, V]) Get(key K) (V, bool)
func (*LRUCacheWithEvictionTTL[K, V]) Peek ¶ added in v0.20.0
func (c *LRUCacheWithEvictionTTL[K, V]) Peek(key K) (V, bool)
func (*LRUCacheWithEvictionTTL[K, V]) Purge ¶ added in v0.20.0
func (c *LRUCacheWithEvictionTTL[K, V]) Purge()
func (*LRUCacheWithEvictionTTL[K, V]) Remove ¶ added in v0.20.0
func (c *LRUCacheWithEvictionTTL[K, V]) Remove(key K)
type LRUCacheWithTTL ¶ added in v0.20.0
type LRUCacheWithTTL[K comparable, V any] struct { // contains filtered or unexported fields }
func NewLRUCacheWithTTL ¶ added in v0.20.0
func NewLRUCacheWithTTL[K comparable, V any](reg prometheus.Registerer, maxEntries int, ttl time.Duration, opts ...CacheWithTTLOptions) *LRUCacheWithTTL[K, V]
func (*LRUCacheWithTTL[K, V]) Add ¶ added in v0.20.0
func (c *LRUCacheWithTTL[K, V]) Add(key K, value V)
func (*LRUCacheWithTTL[K, V]) Close ¶ added in v0.20.0
func (c *LRUCacheWithTTL[K, V]) Close() error
func (*LRUCacheWithTTL[K, V]) Get ¶ added in v0.20.0
func (c *LRUCacheWithTTL[K, V]) Get(key K) (V, bool)
func (*LRUCacheWithTTL[K, V]) Peek ¶ added in v0.20.0
func (c *LRUCacheWithTTL[K, V]) Peek(key K) (V, bool)
func (*LRUCacheWithTTL[K, V]) Purge ¶ added in v0.20.0
func (c *LRUCacheWithTTL[K, V]) Purge()
func (*LRUCacheWithTTL[K, V]) Remove ¶ added in v0.20.0
func (c *LRUCacheWithTTL[K, V]) Remove(key K)
type LRUWithEviction ¶ added in v0.20.0
type LRUWithEviction[K comparable, V any] struct { // contains filtered or unexported fields }
func NewLRUWithEviction ¶ added in v0.20.0
func NewLRUWithEviction[K comparable, V any](reg prometheus.Registerer, maxEntries int, onEvictedCallback func(k K, v V)) (*LRUWithEviction[K, V], error)
NewLRUWithEviction returns a new CacheWithEviction with the given maxEntries.
func (*LRUWithEviction[K, V]) Add ¶ added in v0.20.0
func (c *LRUWithEviction[K, V]) Add(key K, value V)
Add adds a value to the cache.
func (*LRUWithEviction[K, V]) Close ¶ added in v0.20.0
func (c *LRUWithEviction[K, V]) Close()
Close is used to close the underlying LRU by also purging it.
func (*LRUWithEviction[K, V]) Get ¶ added in v0.20.0
func (c *LRUWithEviction[K, V]) Get(key K) (V, bool)
Get looks up a key's value from the cache.
func (*LRUWithEviction[K, V]) Peek ¶ added in v0.20.0
func (c *LRUWithEviction[K, V]) Peek(key K) (V, bool)
Peek returns the value associated with key without updating the "recently used"-ness of that key.
func (*LRUWithEviction[K, V]) Purge ¶ added in v0.20.0
func (c *LRUWithEviction[K, V]) Purge()
Purge is used to completely clear the cache.
func (*LRUWithEviction[K, V]) Remove ¶ added in v0.20.0
func (c *LRUWithEviction[K, V]) Remove(key K)
Remove removes the provided key from the cache.
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)