cache

package
v0.1.8-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2019 License: GPL-3.0 Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheItemRemovalInterval = 5 * time.Second

CacheItemRemovalInterval is the time interval when expired cache item are checked and remove.

Functions

func Sec

func Sec(sec int) time.Time

Sec returns current time + sec

Types

type Cache

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

Cache represents a container for storing objects in memory. Internally it uses an LRU cache allowing older items to be removed eventually. It also supports expiring items that are by default, lazily removed during new additions. To support active expiry checks and removal, use NewActiveCache.

func NewActiveCache

func NewActiveCache(capacity int) *Cache

NewActiveCache creates a new cache instance and begins active item expiration checks and removal.

func NewCache

func NewCache(capacity int) *Cache

NewCache creates a new cache

func (*Cache) Add

func (c *Cache) Add(key, val interface{})

Add adds an item to the cache. It the cache becomes full, the oldest item is deleted to make room for the new value.

func (*Cache) AddMulti

func (c *Cache) AddMulti(exp time.Time, values ...interface{})

AddMulti adds multiple values into the cache. The values are serialized and used as the key.

func (*Cache) AddWithExp

func (c *Cache) AddWithExp(key, val interface{}, expTime time.Time)

AddWithExp adds an item to the cache with an explicit expiration time. Expired items are removed lazily - Whenever Add or AddWithExp are called. An item with an expiry time does not need to be the oldest in the cache before it is removed.

func (*Cache) Get

func (c *Cache) Get(key interface{}) interface{}

Get gets an item and updates the newness of the item

func (*Cache) Has

func (c *Cache) Has(key interface{}) bool

Has checks whether an item is in the cache without updating the newness of the item

func (*Cache) HasMulti

func (c *Cache) HasMulti(values ...interface{}) bool

HasMulti checks whether a multiple valued serialized key exist in the cache..

func (*Cache) Keys

func (c *Cache) Keys() []interface{}

Keys returns all keys in the cache

func (*Cache) Len

func (c *Cache) Len() int

Len returns the length of the cache

func (*Cache) Peek

func (c *Cache) Peek(key interface{}) interface{}

Peek gets an item without updating the newness of the item

func (*Cache) Remove

func (c *Cache) Remove(key interface{})

Remove removes an item from the cache

Jump to

Keyboard shortcuts

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