lazycache package - github.com/bep/lazycache - Go Packages

This section is empty.

This section is empty.

This section is empty.

Cache is a thread-safe resizable LRU cache.

func (c *Cache[K, V]) Delete(key K) bool

Delete deletes the item with given key from the cache, returning if the key was contained.

func (c *Cache[K, V]) DeleteFunc(matches func(key K, item V) bool) int

DeleteFunc deletes all entries for which the given function returns true.

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

Get returns the value associated with key.

func (c *Cache[K, V]) GetOrCreate(key K, create func(key K) (V, error)) (V, bool, error)

GetOrCreate returns the value associated with key, or creates it if it doesn't. It also returns a bool indicating if the value was found in the cache. Note that create, the cache prime function, is called once and then not called again for a given key unless the cache entry is evicted; it does not block other goroutines from calling GetOrCreate, it is not called with the cache lock held. Note that any error returned by create will be returned by GetOrCreate and repeated calls with the same key will receive the same error.

func (c *Cache[K, V]) Len() int

Len returns the number of items in the cache. note that this wil also include values that are not yet ready.

func (c *Cache[K, V]) Resize(size int) (evicted int)

Resize changes the cache size and returns the number of entries evicted.

func (c *Cache[K, V]) Set(key K, value V)

Set associates value with key.

type Options[K comparable, V any] struct {
	
	
	MaxEntries int

	
	OnEvict func(key K, value V)
}

Options holds the cache options.