Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var WithNoRefreshTTL = func(c *cacheConfig) { c.refreshTTL = false }
WithNoRefreshTTL disables the refresh of the TTL when the cache is accessed.
View Source
var WithNow = func(now func() time.Time) Opt {
return func(c *cacheConfig) {
c.now = now
}
}
WithNow sets the function to use to get the current time.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache is a double linked list sorted by expiration time (ascending order) the root (head) node is the node with the lowest expiration time the tail node (end) is the node with the highest expiration time Cleanups are done on Get() calls so if Get() is never invoked then Nodes stay in-memory.
func (*Cache[K, V]) Get ¶
func (c *Cache[K, V]) Get(key K) (zero V)
Get returns the value associated with the key or nil otherwise. Additionally, Get() will refresh the TTL by default and cleanup expired nodes.
Click to show internal directories.
Click to hide internal directories.