cache

package
v0.0.0-...-e49a3f0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Wrapper of the lru cache, adding generics and a size in bytes (approx).

func New

func New[K comparable, V any](capacity int) *Cache[K, V]

Creates a new cache with some sane defaults.

func (*Cache[K, V]) Cached

func (c *Cache[K, V]) Cached(key K, valueCreator func() V) V

Convenience function that gets the entry for the given key, if it is not in the cache, it calls valueCreator and returns what it returns, adding the entry into the cache for next calls.

func (*Cache[K, V]) Delete

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

func (*Cache[K, V]) Get

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

Gets the given key from the cache.

func (*Cache[K, V]) Length

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

func (*Cache[K, V]) Put

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

Puts the given key&value into the cache.

func (*Cache[K, V]) String

func (c *Cache[K, V]) String() string

Returns some stats about the cache, this is relatively expensive because we have to calculate the memory usage of the struct (not fast).

func (*Cache[K, V]) StringWithKeys

func (c *Cache[K, V]) StringWithKeys() string

Returns the same output as String() but with the keys that are cached at the end.

Jump to

Keyboard shortcuts

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