cache

package
v0.0.0-...-89fb8e2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SpearCache

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

SpearCache is a preallocated in memory cache. SpearCache uses a ring queue of a fixed length. All entries in the cache are appended in time order. Entries of the same key don't get updated, but appended instead. When the ring is full, the oldest entries are automatically overwritten. A cache get will retrieve the newest appended entry to the queue, if it exist and is not yet expired.

func NewCache

func NewCache() *SpearCache

NewCache returns an empty SpearCache

func (*SpearCache) Find

func (c *SpearCache) Find(key string) (bool, interface{}, uint64)

Find is used to find a key in the cache. It doesn't require a max age as parameter, this means it will search the entire cache. Find is a costly operation and should only be used when necessary. If the key is found it returns true, the value and the age of the key in nano seconds. If the key is not found, false, nil and zero are returned.

func (*SpearCache) Get

func (c *SpearCache) Get(key string, maxAge uint64) (bool, interface{})

Get is used to retrieve a key from the cache. Get requires the key and the max age of the key in nano seconds. If the key is found true and the value are returned. If the key is not found or is expired, false and nil are returned

func (*SpearCache) Set

func (c *SpearCache) Set(key string, value interface{})

Set is used to set a key value pair into SpearCache The key should always be a string. The value can be everything.

Jump to

Keyboard shortcuts

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