Documentation ¶
Index ¶
- Constants
- type Cache
- func (c Cache) Add(k string, x interface{}, d time.Duration) error
- func (c Cache) Delete(k string)
- func (c Cache) DeleteExpired()
- func (c Cache) Flush()
- func (c Cache) Get(k string) (interface{}, bool)
- func (c Cache) Increment(k string, n int64) error
- func (c Cache) Item() map[string]Item
- 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)
- type Item
Constants ¶
const ( // For use with functions that take an expiration time. NoExpiration time.Duration = -1 DefaultExpiration time.Duration = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
use for outer struct
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) Increment ¶
Increment an item of number (int, TODO other type).Returns an error if the item's value is not an integer, if it was not found, or if it is not possible to increment it by n. To retrieve the incremented value, use one of the specialized methods, e.g. IncrementInt64.
func (Cache) ItemCount ¶
func (c Cache) ItemCount() int
Return the number of items in the cache. Equivalent to len(c.Items()).
func (Cache) OnEvicted ¶
func (c Cache) OnEvicted(f func(string, interface{}))
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.