Documentation
¶
Overview ¶
Package cachekit provides a generic in-memory LRU cache with TTL and tag-based invalidation.
Index ¶
- type Cache
- func (c *Cache[V]) Clear()
- func (c *Cache[V]) Delete(key string) bool
- func (c *Cache[V]) DeleteWhere(predicate func(key string, value V) bool) int
- func (c *Cache[V]) Get(key string) (V, bool)
- func (c *Cache[V]) GetMany(keys []string) map[string]V
- func (c *Cache[V]) GetOrSet(key string, factory func() V, opts ...SetOption) V
- func (c *Cache[V]) Has(key string) bool
- func (c *Cache[V]) InvalidateByTag(tag string) int
- func (c *Cache[V]) Keys() []string
- func (c *Cache[V]) OnEvict(fn func(key string, value V))
- func (c *Cache[V]) Set(key string, value V, opts ...SetOption)
- func (c *Cache[V]) Size() int
- func (c *Cache[V]) Stats() CacheStats
- type CacheStats
- type SetOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[V any] struct { // contains filtered or unexported fields }
Cache is a thread-safe in-memory LRU cache with TTL and tag support.
func New ¶
New creates a new Cache with the given max size and default TTL. A zero TTL means entries don't expire by default.
func (*Cache[V]) DeleteWhere ¶ added in v0.3.0
DeleteWhere removes all entries matching the predicate. Returns the number of entries removed.
func (*Cache[V]) Get ¶
Get retrieves a value from the cache. Returns the value and true if found and not expired.
func (*Cache[V]) GetMany ¶ added in v0.3.0
GetMany returns all cached values for the given keys. Missing or expired keys are omitted.
func (*Cache[V]) GetOrSet ¶ added in v0.3.0
GetOrSet returns the cached value for key, or calls factory to compute and cache it.
func (*Cache[V]) InvalidateByTag ¶
InvalidateByTag removes all entries with the given tag. Returns the count removed.
func (*Cache[V]) OnEvict ¶ added in v0.3.0
OnEvict registers a callback that fires when entries are evicted (LRU or TTL).
func (*Cache[V]) Stats ¶ added in v0.3.0
func (c *Cache[V]) Stats() CacheStats
Stats returns cache hit, miss, and eviction counters.
type CacheStats ¶ added in v0.3.0
CacheStats holds hit, miss, and eviction counters.