Documentation ¶
Index ¶
- type EvictCallback
- type LruCache
- func (c *LruCache) CloneTo(n *LruCache)
- func (c *LruCache) Delete(key any)
- func (c *LruCache) Exist(key any) bool
- func (c *LruCache) Get(key any) (any, bool)
- func (c *LruCache) GetWithExpire(key any) (any, time.Time, bool)
- func (c *LruCache) Set(key any, value any)
- func (c *LruCache) SetWithExpire(key any, value any, expires time.Time)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EvictCallback ¶
EvictCallback is used to get a callback when a cache entry is evicted
type LruCache ¶
type LruCache struct {
// contains filtered or unexported fields
}
LruCache is a thread-safe, in-memory lru-cache that evicts the least recently used entries from memory when (if set) the entries are older than maxAge (in seconds). Use the New constructor to create one.
func (*LruCache) Exist ¶
Exist returns if key exist in cache but not put item to the head of linked list
func (*LruCache) Get ¶
Get returns the any representation of a cached response and a bool set to true if the key was found.
func (*LruCache) GetWithExpire ¶
GetWithExpire returns the any representation of a cached response, a time.Time Give expected expires, and a bool set to true if the key was found. This method will NOT check the maxAge of element and will NOT update the expires.
type Option ¶
type Option func(*LruCache)
Option is part of Functional Options Pattern
func WithStale ¶
WithStale decide whether Stale return is enabled. If this feature is enabled, element will not get Evicted according to `WithAge`.
func WithUpdateAgeOnGet ¶
func WithUpdateAgeOnGet() Option
WithUpdateAgeOnGet update expires when Get element