Documentation ¶
Overview ¶
Package datastore implements structured data storage for wash server functionality.
Index ¶
- type Cache
- type MemCache
- func (cache *MemCache) Delete(matcher *regexp.Regexp) []string
- func (cache *MemCache) Flush()
- func (cache *MemCache) Get(category, key string) (interface{}, error)
- func (cache *MemCache) GetOrUpdate(category, key string, ttl time.Duration, resetTTLOnHit bool, ...) (interface{}, error)
- func (cache *MemCache) Limit(n int) *MemCache
- func (cache *MemCache) WithEvicted(f func(string, interface{})) *MemCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { GetOrUpdate(category, key string, ttl time.Duration, resetTTLOnHit bool, generateValue func() (interface{}, error)) (interface{}, error) Get(category, key string) (interface{}, error) Flush() Delete(matcher *regexp.Regexp) []string }
Cache is an interface for a cache.
type MemCache ¶
type MemCache struct {
// contains filtered or unexported fields
}
MemCache is an in-memory cache. It supports concurrent get/set, as well as the ability to get-or-update cached data in a single transaction to avoid redundant update activity.
func (*MemCache) Flush ¶
func (cache *MemCache) Flush()
Flush deletes all items from the cache. Also resets cache capacity. This operation is significantly slower when cache was configured WithEvicted.
func (*MemCache) Get ¶
Get retrieves the value stored at the given key. If not cached, returns (nil, nil). Even if a nil value is cached, that's unlikely to be a useful value so we don't see a reason to differentiate between absent and nil.
func (*MemCache) GetOrUpdate ¶
func (cache *MemCache) GetOrUpdate(category, key string, ttl time.Duration, resetTTLOnHit bool, generateValue func() (interface{}, error)) (interface{}, error)
GetOrUpdate attempts to retrieve the value stored at the given key. If the value does not exist, then it generates the value using the generateValue function and stores it with the specified ttl. If resetTTLOnHit is true, will reset the cache expiration for the entry. A ttl of -1 means the item never expires, and a ttl of 0 uses the cache default of 1 minute.
func (*MemCache) Limit ¶
Limit configures a limit to how many entries to keep in the cache. Adding a new one evicts the entry closest to expiration.
func (*MemCache) WithEvicted ¶
WithEvicted adds an eviction function that's called on each object as it's evicted to facilitate cleanup.