cache

package
v5.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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 is an in-memory container that uses a LRU eviction strategy. It also supports stale cache, i.e. cache entries have an expiration and when its due the entry is refresh with a background routine, never deleting the old value, only replacing it.

func New

func New(log restql.Logger, size int, loader Loader, options ...Option) *Cache

New constructs an Cache instance.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key interface{}) (interface{}, error)

Get retrieves and entry for the given key.

type Loader

type Loader func(ctx context.Context, key interface{}) (interface{}, error)

Loader is a strategy to fetch values not found or expired in cache.

func ParserCacheLoader

func ParserCacheLoader(p parser.Parser) Loader

ParserCacheLoader is the strategy to load values for the cached parser.

func QueryCacheLoader

func QueryCacheLoader(qr persistence.QueryReader) Loader

QueryCacheLoader is the strategy to load values for the cached query reader.

func TenantCacheLoader

func TenantCacheLoader(mr persistence.MappingsReader) Loader

TenantCacheLoader is the strategy to load values for the cached mappings reader.

type MappingsReaderCache

type MappingsReaderCache struct {
	// contains filtered or unexported fields
}

MappingsReaderCache is a caching wrapper that implements the MappingsReader interface.

func NewMappingsReaderCache

func NewMappingsReaderCache(log restql.Logger, c *Cache) *MappingsReaderCache

NewMappingsReaderCache constructs a MappingsReaderCache instance.

func (*MappingsReaderCache) FromTenant

func (c *MappingsReaderCache) FromTenant(ctx context.Context, tenant string) (map[string]restql.Mapping, error)

FromTenant returns a cached mapping index if present, fetching it otherwise.

type Option

type Option func(c *Cache)

Option is a cache parameter configurator

func WithExpiration

func WithExpiration(expiration time.Duration) Option

WithExpiration sets the time to live of cache entries.

func WithRefreshInterval

func WithRefreshInterval(interval time.Duration) Option

WithRefreshInterval sets the interval between each execution of the background refresh routine.

func WithRefreshQueueLength

func WithRefreshQueueLength(length int) Option

WithRefreshQueueLength sets the maximum queue size of cache entries to be refreshed.

type ParserCache

type ParserCache struct {
	// contains filtered or unexported fields
}

ParserCache is a caching wrapper that implements the Parser interface.

func NewParserCache

func NewParserCache(log restql.Logger, c *Cache) ParserCache

NewParserCache constructs a ParserCache instance.

func (ParserCache) Parse

func (p ParserCache) Parse(queryStr string) (domain.Query, error)

Parse returns a cached QueryRevisions internal representation if present, transforming the query text into one otherwise.

type QueryReaderCache

type QueryReaderCache struct {
	// contains filtered or unexported fields
}

QueryReaderCache is a caching wrapper that implements the QueryReader interface.

func NewQueryReaderCache

func NewQueryReaderCache(log restql.Logger, c *Cache) *QueryReaderCache

NewQueryReaderCache constructs a QueryReaderCache instance.

func (*QueryReaderCache) Get

func (c *QueryReaderCache) Get(ctx context.Context, namespace, id string, revision int) (restql.SavedQuery, error)

Get returns a cached saved query if present, fetching it otherwise.

Jump to

Keyboard shortcuts

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