Documentation ¶
Index ¶
- type CacheItem
- func (item *CacheItem) AccessCount() int64
- func (item *CacheItem) AccessedOn() time.Time
- func (item *CacheItem) CreatedOn() time.Time
- func (item *CacheItem) Data() interface{}
- func (item *CacheItem) KeepAlive()
- func (item *CacheItem) Key() interface{}
- func (item *CacheItem) LifeSpan() time.Duration
- func (item *CacheItem) SetAboutToExpireCallback(f func(interface{}))
- type CacheTable
- func (table *CacheTable) Cache(key interface{}, lifeSpan time.Duration, data interface{}) *CacheItem
- func (table *CacheTable) Count() int
- func (table *CacheTable) Delete(key interface{}) (*CacheItem, error)
- func (table *CacheTable) Exists(key interface{}) bool
- func (table *CacheTable) Flush()
- func (table *CacheTable) SetAboutToDeleteItemCallback(f func(*CacheItem))
- func (table *CacheTable) SetAddedItemCallback(f func(*CacheItem))
- func (table *CacheTable) SetDataLoader(f func(interface{}) *CacheItem)
- func (table *CacheTable) SetLogger(logger *log.Logger)
- func (table *CacheTable) Value(key interface{}) (*CacheItem, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheItem ¶
Structure of an item in the cache. Parameter data contains the user-set value in the cache.
func CreateCacheItem ¶
Returns a newly created CacheItem. Parameter key is the item's cache-key. Parameter lifeSpan determines after which time period without an access the item will get removed from the cache. Parameter data is the item's value.
func (*CacheItem) AccessCount ¶
Returns how often this item has been accessed.
func (*CacheItem) AccessedOn ¶
Returns when this item was last accessed.
func (*CacheItem) Data ¶
func (item *CacheItem) Data() interface{}
Returns the value of this cached item.
func (*CacheItem) KeepAlive ¶
func (item *CacheItem) KeepAlive()
Mark item to be kept for another expireDuration period.
func (*CacheItem) Key ¶
func (item *CacheItem) Key() interface{}
Returns the key of this cached item.
func (*CacheItem) SetAboutToExpireCallback ¶
func (item *CacheItem) SetAboutToExpireCallback(f func(interface{}))
Configures a callback, which will be called right before the item is about to be removed from the cache.
type CacheTable ¶
Structure of a table with items in the cache.
func Cache ¶
func Cache(table string) *CacheTable
Returns the existing cache table with given name or creates a new one if the table does not exist yet.
func (*CacheTable) Cache ¶
func (table *CacheTable) Cache(key interface{}, lifeSpan time.Duration, data interface{}) *CacheItem
Adds a key/value pair to the cache. Parameter key is the item's cache-key. Parameter lifeSpan determines after which time period without an access the item will get removed from the cache. Parameter data is the item's value.
func (*CacheTable) Count ¶
func (table *CacheTable) Count() int
Returns how many items are currently stored in the cache.
func (*CacheTable) Delete ¶
func (table *CacheTable) Delete(key interface{}) (*CacheItem, error)
Delete an item from the cache.
func (*CacheTable) Exists ¶
func (table *CacheTable) Exists(key interface{}) bool
Test whether an item exists in the cache. Unlike the Value method Exists neither tries to fetch data via the loadData callback nor does it keep the item alive in the cache.
func (*CacheTable) SetAboutToDeleteItemCallback ¶
func (table *CacheTable) SetAboutToDeleteItemCallback(f func(*CacheItem))
Configures a callback, which will be called every time an item is about to be removed from the cache.
func (*CacheTable) SetAddedItemCallback ¶
func (table *CacheTable) SetAddedItemCallback(f func(*CacheItem))
Configures a callback, which will be called every time a new item is added to the cache.
func (*CacheTable) SetDataLoader ¶
func (table *CacheTable) SetDataLoader(f func(interface{}) *CacheItem)
Configures a data-loader callback, which will be called when trying to use access a non-existing key.
func (*CacheTable) SetLogger ¶
func (table *CacheTable) SetLogger(logger *log.Logger)
Sets the logger to be used by this cache table.
func (*CacheTable) Value ¶
func (table *CacheTable) Value(key interface{}) (*CacheItem, error)
Get an item from the cache and mark it to be kept alive.