Documentation ¶
Overview ¶
Cache works as thread-safe least recently used (LRU) cache with expiring items on a given TTL span. The TTL gets automatically cycled on each Get() call, which permits the item to stay longer in the cache. There is a soft cap by default on the cache items that get rotated out based on the expiry date.
Index ¶
- Constants
- func Debug() bool
- type Cache
- func (c *Cache) Count() uint
- func (c *Cache) Delete(key string) bool
- func (c *Cache) EnableHardCap()
- func (c *Cache) Expire(key string, data interface{}) error
- func (c *Cache) Get(key string) (interface{}, bool)
- func (c *Cache) Info() []Info
- func (c *Cache) Max() uint
- func (c *Cache) Once(key string, data interface{}) error
- func (c *Cache) Persist(key string, data interface{}) error
- func (c *Cache) Set(key string, data interface{}) error
- type Info
Constants ¶
View Source
const ( // Null disables the ttl Null time.Duration = time.Nanosecond * 0 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct { // Logger defaults to stderr and adds a prefix of "cache: " Logger *log.Logger // contains filtered or unexported fields }
Cache holds all items and configuration.
func New ¶
New creates a new cache instance, taking a ttl and max number for the containing items.
ttl = Null | never expires [~100 years] max = 0 | fallback to default maxItems [64]
func (*Cache) EnableHardCap ¶
func (c *Cache) EnableHardCap()
EnableHardCap disables the ability to rotate the oldest item out of cache to be replaced by a new item.
func (*Cache) Once ¶
Once adds new item to the cache that expires after the first cycle and gets no update on a Get call.
Click to show internal directories.
Click to hide internal directories.