Documentation ¶
Overview ¶
Package cache implements a simple cache where the entries are expired after a given time (5 minutes of disuse by default).
Index ¶
- type Cache
- func (c *Cache) Clear()
- func (c *Cache) Delete(key string) bool
- func (c *Cache) DeletePrefix(prefix string) (deleted int)
- func (c *Cache) Entries() int
- func (c *Cache) Get(key string, create CreateFunc) (value interface{}, err error)
- func (c *Cache) GetMaybe(key string) (value interface{}, found bool)
- func (c *Cache) Pin(key string)
- func (c *Cache) Put(key string, value interface{})
- func (c *Cache) Rename(oldKey, newKey string) (value interface{}, found bool)
- func (c *Cache) SetExpireDuration(d time.Duration) *Cache
- func (c *Cache) SetExpireInterval(d time.Duration) *Cache
- func (c *Cache) Unpin(key string)
- type CreateFunc
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
}
Cache holds values indexed by string, but expired after a given (5 minutes by default).
func (*Cache) Delete ¶ added in v1.55.0
Delete the entry passed in
Returns true if the entry was found
func (*Cache) DeletePrefix ¶ added in v1.55.0
DeletePrefix deletes all entries with the given prefix
Returns number of entries deleted
func (*Cache) Get ¶
func (c *Cache) Get(key string, create CreateFunc) (value interface{}, err error)
Get gets a value named key either from the cache or creates it afresh with the create function.
func (*Cache) Rename ¶ added in v1.52.0
Rename renames the item at oldKey to newKey.
If there was an existing item at newKey then it takes precedence and is returned otherwise the item (if any) at oldKey is returned.
func (*Cache) SetExpireDuration ¶ added in v1.55.0
SetExpireDuration sets the interval at which things expire
If it is less than or equal to 0 then things are never cached
func (*Cache) SetExpireInterval ¶ added in v1.55.0
SetExpireInterval sets the interval at which the cache expiry runs
Set to 0 or a -ve number to disable
type CreateFunc ¶
CreateFunc is called to create new values. If the create function returns an error it will be cached if ok is true, otherwise the error will just be returned, allowing negative caching if required.