Documentation ¶
Index ¶
- Variables
- type Bucket
- func (b *Bucket) Add(key string, item interface{}, expiresIn time.Duration) error
- func (b *Bucket) Delete(key string) error
- func (b *Bucket) Extend(key string, extend time.Duration) error
- func (b *Bucket) Get(key string) (interface{}, error)
- func (b *Bucket) Iterator() *bucketIterator
- func (b *Bucket) Len() int
- func (b *Bucket) Update(key string, item interface{}) error
- type Cache
- func (t *Cache) Add(key string, item interface{}, expiresIn time.Duration) error
- func (c *Cache) Bucket(name string) *Bucket
- func (t *Cache) Delete(key string) error
- func (t *Cache) Extend(key string, extend time.Duration) error
- func (t *Cache) Get(key string) (interface{}, error)
- func (c *Cache) Load(filename string) error
- func (c *Cache) Save(filename string) error
- func (t *Cache) Update(key string, item interface{}) error
- type CacheConfig
- type OnExpires
- type Slot
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCollision is a hash collision error ErrCollision = errors.New("hash collision") // ErrDNE is a "does not exist" error ErrDNE = errors.New("does not exist") )
Functions ¶
This section is empty.
Types ¶
type Bucket ¶ added in v0.1.0
type Bucket struct {
// contains filtered or unexported fields
}
Bucket indexes a group of keys in cache and should be used to manage them
func (*Bucket) Iterator ¶ added in v0.1.0
func (b *Bucket) Iterator() *bucketIterator
Iterator will return an iterator to iterate over the items in the bucket.
type Cache ¶
Cache is a generic in-memory cache
func NewCache ¶
func NewCache(config *CacheConfig) *Cache
NewCache will create and return a pointer to a new Cache object Renewable sets whether
func (*Cache) Add ¶
Add will add a key, value, and expiration duration to the cache. If the key already exists in the collision (i.e. if a collision occurs) then an ErrCollision value will be returned. If you use an expiresIn time of `0` then the item will never be expired from the cache.
func (*Cache) Bucket ¶ added in v0.1.0
Bucket will return the bucket if it exists. It will create and return a new bucket by the name if the bucket does not already exist.
func (*Cache) Delete ¶
Delete will delete a key from the cache. It will return ErrDNE if the key does not exist.
func (*Cache) Extend ¶
Extend will extend the time until expiration for the specified key by the specified duration.
func (*Cache) Get ¶
Get will return the value stored at the key. It will return an ErrDNE value if key is not in cache.
func (*Cache) Load ¶
Load will load an empty cache with the data from the given file. File should contain a gob encoded cached object created via the `Save()` method.
type CacheConfig ¶
type CacheConfig struct { OnExpires OnExpires Refresh bool // extends key's expiration time on usage (for lru-like behavior) RefreshDuration time.Duration CleanDuration time.Duration }
CacheConfig is used to configure a cache