rtcache

package
v0.0.0-...-03d6fc4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Duration to cache an error response.
	DEFAULT_ERRCACHE_EXPIRATION_TIME = time.Minute * 30

	// Interval at which the errcache is cleared of expired entries.
	ERRCACHE_CLEANUP_TIME = time.Minute * 5
)

Variables

This section is empty.

Functions

func PriorityTimeCombined

func PriorityTimeCombined(priority int64) int64

PriorityTimeCombined combines a priority with a timestamp where the priority becomes the most significant digit and the time in Milliseconds the less significant digits. i.e. it allows to process elements of the same priority in order of their timestamps, but ahead of items with less priority.

Types

type MemReadThroughCache

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

MemReadThroughCache implements the ReadThroughCache interface.

func (*MemReadThroughCache) Contains

func (m *MemReadThroughCache) Contains(id string) bool

Contains implements the ReadThroughCache interface.

func (*MemReadThroughCache) Get

func (m *MemReadThroughCache) Get(priority int64, id string) (interface{}, error)

Get implements the ReadThroughCache interface.

func (*MemReadThroughCache) Keys

func (m *MemReadThroughCache) Keys() []string

Keys implements the ReadThroughCache interface.

func (*MemReadThroughCache) Remove

func (m *MemReadThroughCache) Remove(ids []string)

Remove implements the ReadThroughCache interface.

func (*MemReadThroughCache) Warm

func (m *MemReadThroughCache) Warm(priority int64, id string) error

Warm implements the ReadThroughCache interface.

type ReadThroughCache

type ReadThroughCache interface {
	// Get returns the item identified by 'id' or an error if the item
	// cannot be retrieved. If the item is not in the cache a worker function
	// is called to retrieve it.
	Get(priority int64, id string) (interface{}, error)

	// Warm is identical to Get except it does not return the cached elements
	// just makes sure they are in the cache. If an error occurs generating the
	// item desired item via the worker function, an error is returned.
	Warm(priority int64, id string) error

	// Contains returns true if the identified item is currently cached.
	Contains(id string) bool

	// Keys returns the keys of the cache.
	Keys() []string

	// Remove removes the element with the given ids from the cache.
	Remove(ids []string)
}

ReadThroughCache defines a caching work queue with priorities. If the item identified by 'id' is not in the cache then it will call a worker function to calculate it. 'priority' is an positive integer. Lower values have higher priorities, so 0 is the highest priority.

func New

func New(workerFn ReadThroughFunc, maxSize int, nWorkers int) (ReadThroughCache, error)

New returns a new instance of ReadThroughCache that is stored in RAM. nWorkers defines the number of concurrent workers that call wokerFn when requested items are not in RAM.

type ReadThroughFunc

type ReadThroughFunc func(priority int64, id string) (interface{}, error)

WorkerFn defines the function that is called when an item is not in the cache. 'priority' and 'id' are the same that were passed to Get(...).

Jump to

Keyboard shortcuts

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