Documentation ¶
Index ¶
- Constants
- type Cache
- func (cache *Cache) Count() int
- func (cache *Cache) Get(key string) (interface{}, bool)
- func (cache *Cache) Purge()
- func (cache *Cache) Remove(key string) bool
- func (cache *Cache) Set(key string, data interface{})
- func (cache *Cache) SetCheckExpirationCallback(callback checkExpireCallback)
- func (cache *Cache) SetExpirationCallback(callback expireCallback)
- func (cache *Cache) SetNewItemCallback(callback expireCallback)
- func (cache *Cache) SetTTL(ttl time.Duration)
- func (cache *Cache) SetWithTTL(key string, data interface{}, ttl time.Duration)
- func (cache *Cache) SkipTtlExtensionOnHit(value bool)
Constants ¶
const ( // ItemNotExpire Will avoid the item being expired by TTL, but can still be exired by callback etc. ItemNotExpire time.Duration = -1 // ItemExpireWithGlobalTTL will use the global TTL when set. ItemExpireWithGlobalTTL time.Duration = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a synchronized map of items that can auto-expire once stale
func (*Cache) Get ¶
Get is a thread-safe way to lookup items Every lookup, also touches the item, hence extending it's life
func (*Cache) SetCheckExpirationCallback ¶
func (cache *Cache) SetCheckExpirationCallback(callback checkExpireCallback)
SetCheckExpirationCallback sets a callback that will be called when an item is about to expire in order to allow external code to decide whether the item expires or remains for another TTL cycle
func (*Cache) SetExpirationCallback ¶
func (cache *Cache) SetExpirationCallback(callback expireCallback)
SetExpirationCallback sets a callback that will be called when an item expires
func (*Cache) SetNewItemCallback ¶
func (cache *Cache) SetNewItemCallback(callback expireCallback)
SetNewItemCallback sets a callback that will be called when a new item is added to the cache
func (*Cache) SetWithTTL ¶
SetWithTTL is a thread-safe way to add new items to the map with individual ttl
func (*Cache) SkipTtlExtensionOnHit ¶
SkipTtlExtensionOnHit allows the user to change the cache behaviour. When this flag is set to true it will no longer extend TTL of items when they are retrieved using Get, or when their expiration condition is evaluated using SetCheckExpirationCallback.