Documentation ¶
Index ¶
- type Cache
- func (c Cache) Add(key string, value interface{}, expiration time.Duration) error
- func (c Cache) Clear()
- func (c Cache) Delete(key string)
- func (c Cache) DeleteExpired()
- func (c Cache) Get(key string) (interface{}, bool)
- func (c Cache) GetExpiration(key string) time.Duration
- func (c Cache) HasExpired(key string) bool
- func (c Cache) ItemCount() int
- func (c Cache) Set(key string, value interface{}, expiration time.Duration) error
- func (c Cache) SetExpiration(key string, expiration time.Duration)
- type Item
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 thread-safe in-memory key/value store.
func (Cache) Add ¶
Add an item to the cache, existing items will not be overwritten. To overwrite existing items, use Set. If the cache is full, Add will return an error.
func (Cache) Clear ¶
func (c Cache) Clear()
Clear all items from the cache. This reallocate the inderlying array holding the items, so that the memory used by the items is reclaimed.
func (Cache) Delete ¶
func (c Cache) Delete(key string)
Delete an item from the cache. Does nothing if the key is not in the cache.
func (Cache) DeleteExpired ¶
func (c Cache) DeleteExpired()
DeleteExpired deletes all expired items from the cache.
func (Cache) Get ¶
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Cache) GetExpiration ¶
GetExpiration returns the expiration for the given key. Returns zero if the key is not in the cache or the item has already expired.
func (Cache) HasExpired ¶
HasExpired returns true if the item has expired.
func (Cache) ItemCount ¶
func (c Cache) ItemCount() int
ItemCount returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up.
func (Cache) Set ¶
Set adds an item to the cache, replacing any existing item. If expiration is zero, the item never expires. If the cache is full, Set will return an error.
func (Cache) SetExpiration ¶
SetExpiration sets the expiration for the given key. Does nothing if the key is not in the cache.