{"id":44799,"library":"duo-cache","title":"duo-cache","description":"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.","status":"abandoned","version":"2.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/duojs/cache","tags":["javascript","duo","cache"],"install":[{"cmd":"npm install duo-cache","lang":"bash","label":"npm"},{"cmd":"yarn add duo-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add duo-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for LevelDB database operations (read/write/delete cache entries). The `level` package is a deprecated wrapper around LevelUP and LevelDOWN.","package":"level","optional":false},{"reason":"This package is designed for use with Duo; using it standalone outside the Duo build pipeline would lack context.","package":"duo","optional":true}],"imports":[{"note":"The package exports a single constructor function as default. CommonJS require works but may have typing issues. No named exports.","wrong":"const Cache = require('duo-cache')","symbol":"Cache","correct":"import Cache from 'duo-cache'"},{"note":"CommonJS usage; destructuring will result in undefined because there is no named export.","wrong":"const { Cache } = require('duo-cache')","symbol":"Cache","correct":"const Cache = require('duo-cache')"},{"note":"The constructor expects a location string for the LevelDB database directory. Case-sensitive: 'Cache' is capitalized.","wrong":"new cache('/path/to/db')","symbol":"Cache","correct":"new Cache('/path/to/db')"}],"quickstart":{"code":"import Cache from 'duo-cache';\nimport { join } from 'path';\n\nconst location = join(process.cwd(), '.cache');\nconst cache = new Cache(location);\n\n// Set a file's data\ncache.file('app.js', 'console.log(\"hello\");');\n\n// Get a file's data\nconst content = cache.file('app.js');\nconsole.log(content); // 'console.log(\"hello\");'\n\n// Plugin caching example\nconst hash = (s) => s.split('').reduce((a, b) => a + b.charCodeAt(0), 0);\nconst key = [hash('src'), hash({})];\n\n// Check cache\nconst cached = cache.plugin('my-plugin', key);\nif (cached) {\n  console.log('Using cached plugin result:', cached);\n} else {\n  const result = 'transformed content';\n  cache.plugin('my-plugin', key, result);\n}\n\n// Read all cached files into memory (for mapping)\ncache.read();\n\n// Update mapping and persist\nconst mapping = { 'app.js': 'console.log(\"hello\");' };\ncache.update(mapping);\n\n// Clean and close\ntry {\n  cache.clean();\n} catch (e) {\n  console.error(e);\n}","lang":"typescript","description":"Shows basic usage of duo-cache: creating a cache instance, setting/getting files, using plugin caching with custom keys, and cleaning up the database."},"warnings":[{"fix":"Consider migrating to `level` v8+ (`npm i level`) or use a different cache solution such as `cache-manager` or `node-cache`.","message":"The underlying `level` package is deprecated; use `level` v5+ or switch to alternative caching libraries.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Wrap calls in a generator function and use `co()` or migrate to a modern async library. Example: `co(function*() { ... })`.","message":"The API uses generator functions and callbacks, not Promises or async/await, requiring a coroutine runner like `co`.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Only call `clean()` when you explicitly intend to remove the cache directory. Use `fs.unlink` or `level.destroy` for safer cleanup if needed.","message":"The `clean()` method destroys the database directory; calling it accidentally will wipe all cached data.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Loop over files individually or use `update()` to save a mapping object.","message":"The `file()` method does not support multiple files in one call; each call is a single get/set operation.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure the plugin name is consistent (e.g., package name). There is no validation, so typos silently create separate cache entries.","message":"The `plugin()` method expects `name` to match the plugin name; mismatched names will not cause errors but the cache becomes unmanageable.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.1.2':26 '2015':43 'across':69 'activ':87 'appear':34 'around':42 'back':102 'build':19,49 'built':11 'cach':3,6,9,52,65,113,120 'commit':39 'data':22,68 'depend':58,75 'deprec':80 'design':14 'differenti':96 'disk':24,101 'disk-back':100 'duo':2,5,18,47,119 'duo-cach':1,4 'file':54,107 'file-level':106 'flexibl':115 'howev':73 'in-memori':62 'inact':35 'integr':45 'javascript':118 'key':95,116 'last':40 'latest':29 'level':81,108,112 'leveldb':13,72,98 'librari':10 'maintain':88 'make':89 'memori':64 'new':93 'now-deprec':78 'npm':82 'packag':83 'persist':67,103 'pipelin':50 'plugin':55,111 'plugin-level':110 'process':53 'project':33,94 'recent':38 'releas':31 'result':56 'run':70 'scan':59 'simpl':61 'speed':16 'stabl':30 'store':21 'structur':117 'support':104 'unlik':60 'unsuit':91 'updat':41 'use':71,97 'version':25","created_at":"2026-06-07T12:51:53.672011+00:00","updated_at":"2026-06-07T12:51:53.672011+00:00","problems":[{"fix":"Use `import Cache from 'duo-cache'` (ESM) or `const Cache = require('duo-cache')` (CommonJS).","cause":"Importing the default export incorrectly or using destructuring on a CommonJS module that has no named exports.","error":"TypeError: Cache is not a constructor"},{"fix":"Install level: `npm install level` or ensure it's in your package.json dependencies.","cause":"The `level` dependency is not installed or is missing from node_modules.","error":"Error: Cannot find module 'level'"},{"fix":"Wrap the code in a generator function: `co(function*() { ... yield cache.file('id'); ... })`.","cause":"Using `yield` without a generator function or a runner like `co`.","error":"ReferenceError: yield is not defined"},{"fix":"Ensure you call `new Cache(location)` and that the location is writable. If the database is closed, create a new instance.","cause":"The cache instance was destroyed or not properly initialized.","error":"TypeError: cache.clean is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/duojs/cache","github":"https://github.com/duojs/cache","docs":null,"changelog":null,"pypi":null,"npm":"duo-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}