Documentation ¶
Index ¶
- type Cache
- func (c *Cache) Add(key string, value []byte, ttl int64) error
- func (c *Cache) CompareAndReplace(token, key string, value []byte, ttl int64) error
- func (c *Cache) Decrement(key string, initial, offset, ttl int64) error
- func (c *Cache) Delete(key string) error
- func (c *Cache) DeleteMulti(keys []string) map[string]error
- func (c *Cache) Flush() error
- func (c *Cache) Get(key string) ([]byte, string, error)
- func (c *Cache) GetMulti(keys []string) (map[string][]byte, map[string]string, map[string]error)
- func (c *Cache) Increment(key string, initial, offset, ttl int64) error
- func (c *Cache) Replace(key string, value []byte, ttl int64) error
- func (c *Cache) Set(key string, value []byte, ttl int64) error
- func (c *Cache) SetMulti(items map[string][]byte, ttl int64) map[string]error
- func (c *Cache) Touch(key string, ttl int64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a caching implementation that stores the data in memory. The cache will be emptied when the application has run.
func (*Cache) Add ¶
Add an item to the cache. If the item is already cached, the value won't be overwritten.
See the `Set()` function for ttl information.
func (*Cache) CompareAndReplace ¶
CompareAndReplace validates the token with the token in the store. If the tokens match, we will replace the value and return true. If it doesn't, we will not replace the value and return false.
func (*Cache) Decrement ¶
Decrement subtracts a value of offset to the initial value. If the initial value is already set, it will be added to the value currently stored in the cache.
Initial value and offset can't be below 0.
func (*Cache) Delete ¶
Delete will validate if the key actually is stored in the cache. If it is stored, it will remove the item from the cache. If it is not stored, it will return false.
func (*Cache) DeleteMulti ¶
DeleteMulti will delete multiple values at a time. It uses the `Delete` method internally to do so. It will return a map of results to see if the deletion is successful.
func (*Cache) GetMulti ¶
GetMulti gets multiple values from the cache and returns them as a map. It uses `Get` internally to retrieve the data.
func (*Cache) Increment ¶
Increment adds a value of offset to the initial value. If the initial value is already set, it will be added to the value currently stored in the cache.
Initial value and offset can't be below 0.
func (*Cache) Replace ¶
Replace will update and only update the value of a cache key. If the key is not previously used, we will return false.
func (*Cache) Set ¶
Set sets the value of an item, regardless of wether or not the value is already cached.
ttl defines the number of seconds the value should be cached. If ttl is 0, the item will be cached infinitely. If ttl is < 0, the value will be deleted from the cache using the `Delete()` function.