A simple caching library for Node.js (v6.1.0) inspired by the Play cache API, designed to prefer serving stale data over causing a stampede on the backend. Supports both promise- and callback-based usage. Built-in backends: in-memory (default) and memcached (via memcached-elasticache). Released by Groupon, follows semantic versioning. Key differentiators: minimal interface (no multi-get, no deletion), stale-while-revalidate bias, named caches with automatic key prefixes.
npm install cachedNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of cached: creating a named cache, setting/getting values synchronously, using getOrElse with a factory function, and using deferred for callback-style operations.
Copy the value before mutation if needed: const val = await cache.get('key'); const copy = { ...val }Use cached.deferred(done => { ... }) instead of cached.deferred(function(err, result) { ... })Use only the logical key (without prefix) when calling get/set. The prefix is internal.
Use cached.createCache(options) for temporary caches and call cached.dropNamedCache(name) when done.
Use const cached = require('cached'); instead.cached.deferred(done => { done(null, value); })npm install memcached-elasticache
cache.getOrElse('key', () => value) or use cache.set('key', value) first.