Documentation ¶
Overview ¶
Package cache holds definition of Cache used for storing and retrieving data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMissingKey = errors.New("missing key")
ErrMissingKey occurs when cache doesn't have any value under given key.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // Save preserve provided value under given key. Save(key string, value any) // GetSaved retrieve value from given key. GetSaved(key string) (any, error) // Reset turns cache into init state - clears all entries. Reset() // All returns all cache entries. All() map[string]any }
Cache is entity that has ability to store/retrieve arbitrary values.
type ConcurrentCache ¶ added in v0.8.5
type ConcurrentCache struct {
// contains filtered or unexported fields
}
ConcurrentCache is entity that has ability to store and retrieve arbitrary values. Safe for concurrent use.
func NewConcurrentCache ¶ added in v0.8.5
func NewConcurrentCache() *ConcurrentCache
NewConcurrentCache returns pointer to ConcurrentCache safe for concurrent use
func (*ConcurrentCache) All ¶ added in v0.8.5
func (c *ConcurrentCache) All() map[string]any
func (*ConcurrentCache) GetSaved ¶ added in v0.8.5
func (c *ConcurrentCache) GetSaved(key string) (any, error)
func (*ConcurrentCache) Reset ¶ added in v0.8.5
func (c *ConcurrentCache) Reset()
func (*ConcurrentCache) Save ¶ added in v0.8.5
func (c *ConcurrentCache) Save(key string, value any)
type DefaultCache ¶
type DefaultCache struct {
// contains filtered or unexported fields
}
DefaultCache is entity that has ability to store and retrieve arbitrary values. Not safe for concurrent use.
func NewDefaultCache ¶ added in v0.8.5
func NewDefaultCache() *DefaultCache
NewDefaultCache returns pointer to DefaultCache not safe for concurrent use
func (*DefaultCache) All ¶
func (c *DefaultCache) All() map[string]any
All returns all current cache data.
func (*DefaultCache) GetSaved ¶
func (c *DefaultCache) GetSaved(key string) (any, error)
GetSaved returns preserved value if present, error otherwise.
func (*DefaultCache) Reset ¶
func (c *DefaultCache) Reset()
Reset turns cache into initial state - - clears all entries.
func (*DefaultCache) Save ¶
func (c *DefaultCache) Save(key string, value any)
Save preserve value under given key in DefaultCache.