Cache remote data in a LevelUP database with automatic refresh and TTL. Version 2.3.0 is the current stable release. Key features: returns cached value immediately regardless of age, automatically calls the getter periodically to check for new values, emits events when changes are detected, and drops items after a configurable TTL since last access. Unlike level-ttl-cache, this library refreshes values even if the key is not accessed, and emits change events. Breaking change in 2.0.0: switched from sublevel to subleveldown. Maintained by TehShrike, low activity.
npm install levelup-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic setup: create LevelUP database, define a getter function, instantiate Cache, get a value, listen for changes, and stop the cache.
Upgrade to 2.x and ensure your database is migrated or recreated with subleveldown.
Monitor changelog and migrate to any new event names.
Ensure your getter calls cb(err, value) exactly once.
Pass a comparison function that deep-compares values, e.g., using lodash.isEqual.
Ensure you create a LevelUP instance with a LevelDOWN backend, e.g., const db = levelup(leveldown('./path'))Use new Cache(db, getter, options) or ensure db is a LevelUP instance.
Use levelup(dbdown) to wrap your leveldown instance.