Documentation ¶
Index ¶
- Variables
- type Cache
- func (c Cache) Add(k string, x interface{}, d time.Duration) error
- func (c Cache) Decrement(k string, n uint64) (uint64, error)
- func (c Cache) Delete(k string) (found bool)
- func (c Cache) DeleteExpired()
- func (c Cache) Flush()
- func (c Cache) Get(k string) (interface{}, bool)
- func (c Cache) Increment(k string, n uint64) (uint64, error)
- func (c Cache) IncrementFloat(k string, n float64) error
- func (c Cache) Load(r io.Reader) error
- func (c Cache) LoadFile(fname string) error
- func (c Cache) Replace(k string, x interface{}, d time.Duration) error
- func (c Cache) Save(w io.Writer) (err error)
- func (c Cache) SaveFile(fname string) error
- func (c Cache) Set(k string, x interface{}, d time.Duration)
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyExists = fmt.Errorf("item already exists") ErrCacheMiss = fmt.Errorf("item not found") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func New ¶
Return a new cache with a given default expiration duration and cleanup interval. If the expiration duration is less than 1, the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache before their next lookup or before calling 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) Decrement ¶
Decrement an item of type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64 by n. Returns an error if the item's value is not an integer, if it was not found, or if it is not possible to decrement it by n. Stops at 0 on underflow.
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 type int, int8, int16, int32, int64, uintptr, uint, uint8, uint32, or uint64 by n. 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. Wraps around on overlow.
func (Cache) IncrementFloat ¶
Increment an item of type float32 or float64 by n. Returns an error if the item's value is not floating point, if it was not found, or if it is not possible to increment it by n. Pass a negative number to decrement the value.
func (Cache) Load ¶
Add (Gob-serialized) cache items from an io.Reader, excluding any items with keys that already exist in the current cache.
func (Cache) LoadFile ¶
Load and add cache items from the given filename, excluding any items with keys that already exist in the current cache.
func (Cache) Replace ¶
Set a new value for the cache key only if it already exists. Returns an error if it does not.