Documentation
¶
Overview ¶
Package ramcache implements an in-memory key/value cache with expirations based on access and insertion times. It is safe for concurrent use by multiple goroutines.
Index ¶
- Variables
- func Bool(reply interface{}, err error) (bool, error)
- type Ramcache
- func (rc *Ramcache) Count() int
- func (rc *Ramcache) CreatedAt(key string) (t time.Time, err error)
- func (rc *Ramcache) Delete(key string) error
- func (rc *Ramcache) Each(f func(key string, value interface{}))
- func (rc *Ramcache) Freeze()
- func (rc *Ramcache) Get(key string) (interface{}, error)
- func (rc *Ramcache) GetNoAccess(key string) (interface{}, error)
- func (rc *Ramcache) Keys() []string
- func (rc *Ramcache) Remove(key string) (interface{}, error)
- func (rc *Ramcache) Set(key string, obj interface{}) error
- func (rc *Ramcache) Shutdown()
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("ramcache: key not found in cache")
ErrNotFound is returned when a key isn't found in the cache.
Functions ¶
Types ¶
type Ramcache ¶
type Ramcache struct { TTL time.Duration MaxAge time.Duration sync.RWMutex // contains filtered or unexported fields }
Ramcache is an in-memory key/value store. It has two configuration durations: TTL (time to live) and MaxAge. Ramcache removes any objects that haven't been accessed in the TTL duration. Ramcache removes (on get) any objects that were created more than MaxAge time ago. This allows you to keep recently accessed objects cached but also delete them once they have been in the cache for MaxAge duration.
func New ¶
func New() *Ramcache
New creates a Ramcache with a TTL of 5 minutes. You can change this by setting the result's TTL to any time.Duration you want. You can also set the MaxAge on the result.
func (*Ramcache) Freeze ¶
func (rc *Ramcache) Freeze()
Freeze stops Ramcache from removing any expired entries.
func (*Ramcache) GetNoAccess ¶
GetNoAccess retrieves a value from the cache, but does not update the access time.