Documentation
¶
Index ¶
- func NewCacheUnit(data interface{}, isValid func(u *unit) bool) *unit
- type CacheImpl
- func (c *CacheImpl) Clear()
- func (c *CacheImpl) Delete(key string) error
- func (c *CacheImpl) Get(key string) (interface{}, bool)
- func (c *CacheImpl) GetDefault(key string, d interface{}) interface{}
- func (c *CacheImpl) Put(key string, unit *unit) error
- func (c *CacheImpl) PutExpiry(key string, unit *unit, expiry time.Time) error
- func (c *CacheImpl) Set(key string, unit *unit) error
- func (c *CacheImpl) SetExpiry(key string, unit *unit, expiry time.Time) error
- type Cacher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCacheUnit ¶
func NewCacheUnit(data interface{}, isValid func(u *unit) bool) *unit
NewCacheUnit creates a new cacheable chunk of data. Optionally a function `isValid` can be provided to check if a `*unit` is valid. If this function fails the cache will purge the key.
Types ¶
type CacheImpl ¶
type CacheImpl struct {
// contains filtered or unexported fields
}
CacheImpl implements patrickmn's `go-cache`.
func (*CacheImpl) GetDefault ¶
type Cacher ¶
type Cacher interface {
// Put sets, if not present, the key to the `*cache.Unit`, with default
// expiry. May return an error depending on impl.
Put(key string, unit *unit) error
// PutExpiry sets, if not present, the key to the `*cache.Unit`, with
// given expiry. May return an error depending on impl.
PutExpiry(key string, unit *unit, expiry time.Time) error
// Set sets, the key to the `*cache.Unit`, present or not, with default
// expiry. May return an error depending on impl.
Set(key string, unit *unit) error
// SetExpiry sets, the key to the `*cache.Unit`, present or not, with
// given expiry. May return an error depending on impl.
SetExpiry(key string, unit *unit, expiry time.Time) error
// Get returns the key's unit's value if valid. Checks the `isValid`
// function & expiry times. Bool indicates if present (& valid).
Get(key string) (interface{}, bool)
// GetDefault returns the key's unit's value if valid. Checks the `isValid`
// function & expiry times. If not present (or valid) `d` is returned.
GetDefault(key string, d interface{}) interface{}
// Delete will remove the key from the cache. May return an error depending
// on impl.
Delete(key string) error
Clear()
}
Cacher represents all cache implementations, barebones interoperable functions, for any implementation that may be used down the line.
Click to show internal directories.
Click to hide internal directories.