Documentation
¶
Index ¶
- type Cache
- func (c *Cache) Add(key interface{}, val interface{}, exp time.Duration) error
- func (c *Cache) Cap() int
- func (c *Cache) Clear()
- func (c *Cache) Contains(key interface{}) bool
- func (c *Cache) Get(key interface{}) (interface{}, bool)
- func (c *Cache) Keys() []interface{}
- func (c *Cache) Len() int
- func (c *Cache) Peek(key interface{}) (interface{}, bool)
- func (c *Cache) Remove(key interface{}) error
- func (c *Cache) RemoveOldest() (k interface{}, v interface{}, ok bool)
- func (c *Cache) Resize(size int) int
- type Config
- type Item
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// CleanInterval is the time duration to make cache empty.
CleanInterval time.Duration
// ExpirationTimeoutInterval indicates the time to delete expired items.
ExpirationTimeoutInterval time.Duration
// contains filtered or unexported fields
}
Cache is the main cache type.
func New ¶
New creates a new cache and returns it with error type. Capacity of the cache needs to be more than zero.
func (*Cache) Contains ¶
Contains checks the given key and returns the information that it exists on cache or not. Calling this function doesn't change the access order of the cache.
func (*Cache) Get ¶
Get retrieves the data from list and returns it with bool information which indicates whether found. If there is no such data in cache, it returns nil and false.
func (*Cache) Keys ¶
func (c *Cache) Keys() []interface{}
Keys returns all keys in cache. It does not change frequency of the item access.
func (*Cache) Peek ¶ added in v0.2.0
Peek returns the given key without updating access frequency of the item.
func (*Cache) Remove ¶
Remove deletes the item from the cache. Updates the length of the cache decrementing by one.
func (*Cache) RemoveOldest ¶ added in v0.3.0
RemoveOldest removes the least recently used one. Returns removed key, value, and bool value that indicates whether remove operation is done successfully.