datastore

package
v0.0.0-...-2bc12df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package datastore implements structured data storage for wash server functionality.

Index

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 NewMemCache

func NewMemCache() *MemCache

NewMemCache creates a new MemCache object

func (*MemCache) Delete

func (cache *MemCache) Delete(matcher *regexp.Regexp) []string

Delete removes entries from the cache that match the provided regexp.

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

func (cache *MemCache) Get(category, key string) (interface{}, error)

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

func (cache *MemCache) Limit(n int) *MemCache

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

func (cache *MemCache) WithEvicted(f func(string, interface{})) *MemCache

WithEvicted adds an eviction function that's called on each object as it's evicted to facilitate cleanup.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL