Registry / storage / duo-cache

duo-cache

JSON →
library2.1.2jsnpmunverified

duo-cache is a caching library built on LevelDB, designed to speed up Duo builds by storing data on disk. Version 2.1.2 is the latest stable release; the project appears inactive with no recent commits (last updated around 2015). It integrates with Duo's build pipeline to cache processed files, plugin results, and dependency scans. Unlike simple in-memory caches, it persists data across runs using LevelDB. However, it depends on the now-deprecated `level` npm package and is not actively maintained, making it unsuitable for new projects. Key differentiators: uses LevelDB for disk-backed persistence, supports both file-level and plugin-level caching with flexible key structures.

npm install duo-cache
INSTALL
IMPORT
SIG · DUO-CACHE
D
duo-cache
storagejavascriptv2.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Cache
import Cache from 'duo-cache'
const Cache = require('duo-cache')
The package exports a single constructor function as default. CommonJS require works but may have typing issues. No named exports.
Cache
const Cache = require('duo-cache')
const { Cache } = require('duo-cache')
CommonJS usage; destructuring will result in undefined because there is no named export.
Cache
new Cache('/path/to/db')
new cache('/path/to/db')
The constructor expects a location string for the LevelDB database directory. Case-sensitive: 'Cache' is capitalized.

Shows basic usage of duo-cache: creating a cache instance, setting/getting files, using plugin caching with custom keys, and cleaning up the database.

import Cache from 'duo-cache'; import { join } from 'path'; const location = join(process.cwd(), '.cache'); const cache = new Cache(location); // Set a file's data cache.file('app.js', 'console.log("hello");'); // Get a file's data const content = cache.file('app.js'); console.log(content); // 'console.log("hello");' // Plugin caching example const hash = (s) => s.split('').reduce((a, b) => a + b.charCodeAt(0), 0); const key = [hash('src'), hash({})]; // Check cache const cached = cache.plugin('my-plugin', key); if (cached) { console.log('Using cached plugin result:', cached); } else { const result = 'transformed content'; cache.plugin('my-plugin', key, result); } // Read all cached files into memory (for mapping) cache.read(); // Update mapping and persist const mapping = { 'app.js': 'console.log("hello");' }; cache.update(mapping); // Clean and close try { cache.clean(); } catch (e) { console.error(e); }
Debug
Known issues
deprecatedThe underlying `level` package is deprecated; use `level` v5+ or switch to alternative caching libraries.
fix
Consider migrating to `level` v8+ (`npm i level`) or use a different cache solution such as `cache-manager` or `node-cache`.
affects: >=1.0.0
breakingThe API uses generator functions and callbacks, not Promises or async/await, requiring a coroutine runner like `co`.
fix
Wrap calls in a generator function and use `co()` or migrate to a modern async library. Example: `co(function*() { ... })`.
affects: >=1.0.0
breakingThe `clean()` method destroys the database directory; calling it accidentally will wipe all cached data.
fix
Only call `clean()` when you explicitly intend to remove the cache directory. Use `fs.unlink` or `level.destroy` for safer cleanup if needed.
affects: >=1.0.0
gotchaThe `file()` method does not support multiple files in one call; each call is a single get/set operation.
fix
Loop over files individually or use `update()` to save a mapping object.
affects: >=1.0.0
deprecatedThe `plugin()` method expects `name` to match the plugin name; mismatched names will not cause errors but the cache becomes unmanageable.
fix
Ensure the plugin name is consistent (e.g., package name). There is no validation, so typos silently create separate cache entries.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cache is not a constructor
Importing the default export incorrectly or using destructuring on a CommonJS module that has no named exports.
fix
Use `import Cache from 'duo-cache'` (ESM) or `const Cache = require('duo-cache')` (CommonJS).
Error: Cannot find module 'level'
The `level` dependency is not installed or is missing from node_modules.
fix
Install level: `npm install level` or ensure it's in your package.json dependencies.
ReferenceError: yield is not defined
Using `yield` without a generator function or a runner like `co`.
fix
Wrap the code in a generator function: `co(function*() { ... yield cache.file('id'); ... })`.
TypeError: cache.clean is not a function
The cache instance was destroyed or not properly initialized.
fix
Ensure you call `new Cache(location)` and that the location is writable. If the database is closed, create a new instance.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies
levelrequiredUsed for LevelDB database operations (read/write/delete cache entries). The `level` package is a deprecated wrapper around LevelUP and LevelDOWN.
duooptionalThis package is designed for use with Duo; using it standalone outside the Duo build pipeline would lack context.
Agent activity
30 hits · last 30 days
node
26
Amazon
1
Resources
duo-cache — npm install duo-cache · libregistry