Documentation ¶
Index ¶
- Variables
- func Sec(sec int) time.Time
- type Cache
- func (c *Cache) Add(key, val interface{})
- func (c *Cache) AddMulti(exp time.Time, values ...interface{})
- func (c *Cache) AddWithExp(key, val interface{}, expTime time.Time)
- func (c *Cache) Get(key interface{}) interface{}
- func (c *Cache) Has(key interface{}) bool
- func (c *Cache) HasMulti(values ...interface{}) bool
- func (c *Cache) Keys() []interface{}
- func (c *Cache) Len() int
- func (c *Cache) Peek(key interface{}) interface{}
- func (c *Cache) Remove(key interface{})
Constants ¶
This section is empty.
Variables ¶
var CacheItemRemovalInterval = 5 * time.Second
CacheItemRemovalInterval is the time interval when expired cache item are checked and remove.
Functions ¶
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 ¶
NewActiveCache creates a new cache instance and begins active item expiration checks and removal.
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 ¶
AddMulti adds multiple values into the cache. The values are serialized and used as the key.
func (*Cache) AddWithExp ¶
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 ¶
Has checks whether an item is in the cache without updating the newness of the item
func (*Cache) HasMulti ¶
HasMulti checks whether a multiple valued serialized key exist in the cache..