Documentation ¶
Overview ¶
Package cache
Package cache ¶
Package cache
Index ¶
- 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) GetWithExpiration(k string) (interface{}, time.Time, bool)
- func (c Cache) ItemCount() int
- func (c Cache) Items() map[string]Item
- func (c Cache) Load(r io.Reader) error
- func (c Cache) LoadFile(fname string) error
- func (c Cache) OnEvicted(f func(string, interface{}))
- 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)
- func (c Cache) SetDefault(k string, x interface{})
- type Item
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
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) GetWithExpiration ¶
GetWithExpiration returns an item and its expiration time from the cache. It returns the item or nil, the expiration time if one is set (if the item never expires a zero value for time.Time is returned), and a bool indicating whether the key was found.
func (Cache) ItemCount ¶
func (c Cache) ItemCount() int
Returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up.
func (Cache) Load ¶
Add (Gob-serialized) cache items from an io.Reader, excluding any items with keys that already exist (and haven't expired) in the current cache.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Cache) LoadFile ¶
Load and add cache items from the given filename, excluding any items with keys that already exist in the current cache.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
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.
func (Cache) 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) Save ¶
Write the cache's items (using Gob) to an io.Writer.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Cache) SaveFile ¶
Save the cache's items to the given filename, creating the file if it doesn't exist, and overwriting it if it does.
NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
func (Cache) SetDefault ¶
func (c Cache) SetDefault(k string, x interface{})
Add an item to the cache, replacing any existing item, using the default expiration.