cache

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNoopCache

func NewNoopCache[K comparable, V any]() *noopCache[K, V]

Types

type CacheWithTTLOptions

type CacheWithTTLOptions struct {
	UpdateDeadlineOnGet bool
	RemoveExpiredOnAdd  bool
}

type LRUCache

type LRUCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewLRUCache

func NewLRUCache[K comparable, V any](reg prometheus.Registerer, maxEntries int) *LRUCache[K, V]

func (*LRUCache[K, V]) Add

func (c *LRUCache[K, V]) Add(key K, value V)

func (*LRUCache[K, V]) Close

func (c *LRUCache[K, V]) Close() error

func (*LRUCache[K, V]) Get

func (c *LRUCache[K, V]) Get(key K) (V, bool)

func (*LRUCache[K, V]) Peek

func (c *LRUCache[K, V]) Peek(key K) (V, bool)

Peek returns the value associated with key without updating the "recently used"-ness of that key.

func (*LRUCache[K, V]) Purge

func (c *LRUCache[K, V]) Purge()

func (*LRUCache[K, V]) Remove

func (c *LRUCache[K, V]) Remove(key K)

type LRUCacheWithEvictionTTL

type LRUCacheWithEvictionTTL[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewLRUCacheWithEvictionTTL

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

func (c *LRUCacheWithEvictionTTL[K, V]) Add(key K, value V)

func (*LRUCacheWithEvictionTTL[K, V]) Close

func (c *LRUCacheWithEvictionTTL[K, V]) Close() error

func (*LRUCacheWithEvictionTTL[K, V]) Get

func (c *LRUCacheWithEvictionTTL[K, V]) Get(key K) (V, bool)

func (*LRUCacheWithEvictionTTL[K, V]) Peek

func (c *LRUCacheWithEvictionTTL[K, V]) Peek(key K) (V, bool)

func (*LRUCacheWithEvictionTTL[K, V]) Purge

func (c *LRUCacheWithEvictionTTL[K, V]) Purge()

func (*LRUCacheWithEvictionTTL[K, V]) Remove

func (c *LRUCacheWithEvictionTTL[K, V]) Remove(key K)

type LRUCacheWithTTL

type LRUCacheWithTTL[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewLRUCacheWithTTL

func NewLRUCacheWithTTL[K comparable, V any](reg prometheus.Registerer, maxEntries int, ttl time.Duration, opts ...CacheWithTTLOptions) *LRUCacheWithTTL[K, V]

func (*LRUCacheWithTTL[K, V]) Add

func (c *LRUCacheWithTTL[K, V]) Add(key K, value V)

func (*LRUCacheWithTTL[K, V]) Close

func (c *LRUCacheWithTTL[K, V]) Close() error

func (*LRUCacheWithTTL[K, V]) Get

func (c *LRUCacheWithTTL[K, V]) Get(key K) (V, bool)

func (*LRUCacheWithTTL[K, V]) Peek

func (c *LRUCacheWithTTL[K, V]) Peek(key K) (V, bool)

func (*LRUCacheWithTTL[K, V]) Purge

func (c *LRUCacheWithTTL[K, V]) Purge()

func (*LRUCacheWithTTL[K, V]) Remove

func (c *LRUCacheWithTTL[K, V]) Remove(key K)

type LRUWithEviction

type LRUWithEviction[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewLRUWithEviction

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

func (c *LRUWithEviction[K, V]) Add(key K, value V)

Add adds a value to the cache.

func (*LRUWithEviction[K, V]) Close

func (c *LRUWithEviction[K, V]) Close()

Close is used to close the underlying LRU by also purging it.

func (*LRUWithEviction[K, V]) Get

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

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

func (c *LRUWithEviction[K, V]) Purge()

Purge is used to completely clear the cache.

func (*LRUWithEviction[K, V]) Remove

func (c *LRUWithEviction[K, V]) Remove(key K)

Remove removes the provided key from the cache.

type LoaderFunc

type LoaderFunc[K comparable, V any] func(K) (V, error)

type LoadingLRUCacheWithTTL

type LoadingLRUCacheWithTTL[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewLoadingLRUCacheWithTTL

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

func (c *LoadingLRUCacheWithTTL[K, V]) Close() error

func (*LoadingLRUCacheWithTTL[K, V]) Get

func (c *LoadingLRUCacheWithTTL[K, V]) Get(key K) (V, error)

type LoadingOnceCache

type LoadingOnceCache[K comparable, V any] struct {
	*LoadingLRUCacheWithTTL[K, V]
	// contains filtered or unexported fields
}

func NewLoadingOnceCache

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

func (c *LoadingOnceCache[K, V]) Get(key K) (V, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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