Documentation
¶
Index ¶
- func Options() *options
- type Cache
- type Key
- type LRUCache
- type TTLCache
- func (c *TTLCache[K, V]) Delete(key K)
- func (c *TTLCache[K, V]) ForEach(f func(key K, value V) error) error
- func (c *TTLCache[K, V]) ForceCleanup()
- func (c *TTLCache[K, V]) Get(key K) (V, bool)
- func (c *TTLCache[K, V]) Has(key K) bool
- func (c *TTLCache[K, V]) Set(key K, value V, opts *options) bool
- func (c *TTLCache[K, V]) Size() int
- type TTLCacheAttrs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache[K Key, V any] interface { Get(key K) (V, bool) Set(key K, value V, opts *options) bool Delete(key K) Has(key K) bool ForEach(f func(key K, value V) error) error Size() int }
Cache is the unified interface for all cache implementations.
type Key ¶ added in v1.5.2
type Key interface {
comparable
Bytes() []byte
}
Key is the constraint for cache keys. Bytes() is required instead of String() because sharded caches use it to compute the shard index, and raw bytes are significantly cheaper to hash than a formatted string — e.g. IPKey.String() formats an IP address and allocates, while IPKey.Bytes() returns the underlying array slice with zero allocation.
type TTLCache ¶
func NewTTLCache ¶
func NewTTLCache[K Key, V any]( attrs TTLCacheAttrs, ) *TTLCache[K, V]
func (*TTLCache[K, V]) ForceCleanup ¶
func (c *TTLCache[K, V]) ForceCleanup()