Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LRUCache ¶
type LRUCache struct {
// OnEvicted optionally specifies a callback function to be
// executed when an entry is purged from the cache.
OnEvicted func(key string, value any)
// contains filtered or unexported fields
}
LRUCache is "groupcache/lru"-like cache. The difference is that "groupcache/lru" immediately finalizes theevicted contents using OnEvicted callback but our version strictly tracks the reference counts of contents and calls OnEvicted when nobody refers to the evicted contents.
func (*LRUCache) Add ¶
Add adds object to the cache and returns the cached contents with incrementing the reference count. If the specified content already exists in the cache, this sets `added` to false and returns "already cached" content (i.e. doesn't replace the content with the new one). Client must call `done` callback to decrease the counter when the value will no longer be used.
type TTLCache ¶
type TTLCache struct {
// OnEvicted optionally specifies a callback function to be
// executed when an entry is purged from the cache.
OnEvicted func(key string, value any)
// contains filtered or unexported fields
}
TTLCache is a ttl-based cache with reference counters. Each elements is deleted as soon as expiering the configured ttl.
func NewTTLCache ¶
NewTTLCache creates a new ttl-based cache.
func (*TTLCache) Add ¶
Add adds object to the cache and returns the cached contents with incrementing the reference count. If the specified content already exists in the cache, this sets `added` to false and returns "already cached" content (i.e. doesn't replace the content with the new one). Client must call `done` callback to decrease the counter when the value will no longer be used.