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.
ErrNotFound is returned when a key isn't found in the cache.
Bool is a convenience method to type assert a Ramcache reply into a boolean value.
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.
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.
Count returns the number of elements in the cache.
CreatedAt returns the time the key was inserted into the cache.
Delete deletes an item from the cache.
Each will call f for every entry in the cache.
Freeze stops Ramcache from removing any expired entries.
Get retrieves a value from the cache.
GetNoAccess retrieves a value from the cache, but does not update the access time.
Keys returns all the keys in the cache.
Remove deletes an item from the cache and returns it.
Set inserts a value in the cache. If an object already exists, it will be replaced, but the createdAt timestamp won't change.
Shutdown cleanly stops any background work, allowing Ramcache to be garbage collected.