Documentation ¶
Overview ¶
Cache works as thread-safe least recently used (LRU) cache with expiring items on a given TTL span. The TTL gets automatically re-cycled on each Get() call, which permits to stay longer in the cache.
Index ¶
- Constants
- type Cache
- func (c *Cache) Count() uint
- func (c *Cache) Debug() bool
- func (c *Cache) Delete(key string) bool
- 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 ¶
This section is empty.
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) Debug ¶
Debug toggles (enables/disables) debug output through Logger and returns either true if enabled or respectively false if disabled.
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.