Documentation ¶
Index ¶
- Constants
- type Cache
- func (c Cache) Add(k string, x interface{}, d time.Duration) error
- func (c Cache) Clear()
- func (c Cache) Delete(k string)
- func (c Cache) DeleteExpired()
- func (c Cache) Get(k string) (interface{}, bool)
- func (c Cache) ItemCount() int
- func (c Cache) OnEvicted(f func(string, interface{}))
- func (c Cache) Replace(k string, x interface{}, d time.Duration) error
- func (c Cache) Set(k string, x interface{}, d time.Duration)
- func (c Cache) UpdateExpiration(k string, Expiration int64) error
- type Item
Constants ¶
const ( // NoExpiration for use with functions that take an expiration time. NoExpiration time.Duration = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache a cache struct
func NewCache ¶
NewCache return a new cache with a given cleanup interval. If the cleanup interval is less than one, expired items are not deleted from the cache before calling c.DeleteExpired().
func (Cache) Add ¶
Add an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired. Returns an error otherwise.
func (Cache) Delete ¶
func (c Cache) Delete(k string)
Delete an item from the cache. Does nothing if the key is not in the cache.
func (Cache) DeleteExpired ¶
func (c Cache) DeleteExpired()
Delete all expired items from the cache.
func (Cache) Get ¶
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Cache) ItemCount ¶
func (c Cache) ItemCount() int
ItemCount returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up. Equivalent to len(c.Items()).
func (Cache) OnEvicted ¶
func (c Cache) OnEvicted(f func(string, interface{}))
OnEvicted Sets an (optional) function that is called with the key and value when an item is evicted from the cache. (Including when it is deleted manually, but not when it is overwritten.) Set to nil to disable.
func (Cache) Replace ¶
Replace Set a new value for the cache key only if it already exists, and the existing item hasn't expired. Returns an error otherwise.
func (Cache) Set ¶
Set Add an item to the cache, replacing any existing item. If it is -1 (NoExpiration), the item never expires.
func (Cache) UpdateExpiration ¶
UpdateExpiration