Documentation ¶
Index ¶
- type Cache
- func (c *Cache[K, V]) Cached(key K, valueCreator func() V) V
- func (c *Cache[K, V]) Delete(key K)
- func (c *Cache[K, V]) Get(key K) (V, bool)
- func (c *Cache[K, V]) Length() int
- func (c *Cache[K, V]) Put(key K, value V)
- func (c *Cache[K, V]) String() string
- func (c *Cache[K, V]) StringWithKeys() string
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]) Put ¶
func (c *Cache[K, V]) Put(key K, value V)
Puts the given key&value into the cache.
func (*Cache[K, V]) 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 ¶
Returns the same output as String() but with the keys that are cached at the end.
Click to show internal directories.
Click to hide internal directories.