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 (*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.