Documentation ¶
Index ¶
- type Cache
- type EvictCallback
- type LruCache
- func (c *LruCache) CloneTo(n *LruCache)
- func (c *LruCache) Delete(key interface{})
- func (c *LruCache) Exist(key interface{}) bool
- func (c *LruCache) Get(key interface{}) (interface{}, bool)
- func (c *LruCache) GetWithExpire(key interface{}) (interface{}, time.Time, bool)
- func (c *LruCache) Set(key interface{}, value interface{})
- func (c *LruCache) SetWithExpire(key interface{}, value interface{}, expires time.Time)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache store element with a expired time
func (Cache) Get ¶
func (c Cache) Get(key interface{}) interface{}
Get element in Cache, and drop when it expired
func (Cache) GetWithExpire ¶ added in v0.11.0
GetWithExpire element in Cache with Expire Time
type EvictCallback ¶ added in v0.17.0
type EvictCallback = func(key interface{}, value interface{})
EvictCallback is used to get a callback when a cache entry is evicted
type LruCache ¶ added in v0.16.0
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 NewLRUCache ¶ added in v0.16.0
NewLRUCache creates an LruCache
func (*LruCache) Delete ¶ added in v0.16.0
func (c *LruCache) Delete(key interface{})
Delete removes the value associated with a key.
func (*LruCache) Exist ¶ added in v0.16.0
Exist returns if key exist in cache but not put item to the head of linked list
func (*LruCache) Get ¶ added in v0.16.0
Get returns the interface{} representation of a cached response and a bool set to true if the key was found.
func (*LruCache) GetWithExpire ¶ added in v0.20.0
GetWithExpire returns the interface{} 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.
func (*LruCache) Set ¶ added in v0.16.0
func (c *LruCache) Set(key interface{}, value interface{})
Set stores the interface{} representation of a response for a given key.
func (*LruCache) SetWithExpire ¶ added in v0.20.0
SetWithExpire stores the interface{} representation of a response for a given key and given expires. The expires time will round to second.
type Option ¶ added in v0.16.0
type Option func(*LruCache)
Option is part of Functional Options Pattern
func WithEvict ¶ added in v0.17.0
func WithEvict(cb EvictCallback) Option
WithEvict set the evict callback
func WithStale ¶ added in v0.20.0
WithStale decide whether Stale return is enabled. If this feature is enabled, element will not get Evicted according to `WithAge`.
func WithUpdateAgeOnGet ¶ added in v0.16.0
func WithUpdateAgeOnGet() Option
WithUpdateAgeOnGet update expires when Get element