Documentation ¶
Index ¶
- Constants
- type Cache
- func (c *Cache) Add(k string, v interface{}, d time.Duration) error
- func (c *Cache) Get(k string) (interface{}, bool)
- func (c *Cache) GetAll() map[string]Item
- func (c *Cache) GetWithExpiration(k string) (interface{}, time.Time, bool)
- func (c *Cache) Replace(k string, v interface{}, d time.Duration) error
- func (c *Cache) Set(k string, v interface{}, d time.Duration)
- func (c *Cache) SetDefault(k string, v interface{})
- type Item
Constants ¶
const ( DefaultExpiration = 0 NoExpiration = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func (*Cache) Add ¶
Add an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired. Returns an error otherwise.
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) GetWithExpiration ¶
GetWithExpiration returns an item and its expiration time from the cache. It returns the item or nil, the expiration time if one is set (if the item never expires a zero value for time.Time is returned), and a bool indicating whether the key was found.
func (*Cache) Replace ¶
Set a new value for the cache key only if it already exists, and the existing item hasn't expired. Returns an error otherwise.
func (*Cache) SetDefault ¶
Add an item to the cache, replacing any existing item, using the default expiration.