uber-cache-namespace
v0.0.0
Published
Wrapper for uber-cache engines providing namespaces
Readme
uber-cache-namespace — Wrapper for uber-cache providing namespacing
Installation
npm install uber-cache-namespaceUsage
uber-cache-namespace prevents accidental overriding of data when more than one application uses the same cache engine (eg. memcached)
var cache = new UberCacheNamespace('my-namespace', myUberCacheEngine)
cache.set('some-key', someData, ttl, function (err, savedValue) {
// writes to myUberCacheEngine with my-namespace- prefixed to the key
cache.get('some-key', function (error, data) {
// retrieves data — you don’t have to worry about the prefix
}
})
cache.on('miss', function (key) {
// key will not have the prefix prepended
})
API
Functions
set(key, value, ttl, callback)ttl milliseconds until expiry. Optional
get(key, callback)delete(key, callback)
Please be aware that although some uber-cache engines support dump, size, and clear,
uber-cache-namespace does not. These methods are implemented only to make testing possible.
Events
miss(key)— Emitted when aget(key)fails to find a valid cached item with that key.hit(key, value, ttl)— Emitted when aget(key)finds a valid item in the cache.stale(key, value, ttl)— Emitted when aget(key)can’t find a valid item but a stale item still exists.delete(key)— Emitted when adelete(key)deletes an item.
Credits
License
Licensed under the New BSD License
