Registry / storage / level-content-cache

level-content-cache

JSON →
library1.3.3jsnpmunverified

Package for caching mutable resources into a content-addressable store using LevelDB. Version 1.3.3 is stable but appears unmaintained (last update years ago). It combines a content-addressable store (CAS) with a LevelDB-backed caching layer, allowing efficient retrieval and storage of resources keyed by content hash. Supports customizable getter functions for fetching resources. Different from simple LevelDB caches by leveraging CAS for deduplication and integrity. Lightweight and suitable for Node.js applications needing persistent, content-addressed caching.

npm install level-content-cache
INSTALL
IMPORT
SIG · LEVEL-CONTENT-CACH
L
level-content-cache
storagejavascriptv1.3.3
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.

default
const ContentCache = require('level-content-cache')
import ContentCache from 'level-content-cache'
CJS only; no ESM export or TypeScript types. Use require().
ContentCache
const ContentCache = require('level-content-cache')
import { ContentCache } from 'level-content-cache'
Default export, not named. Always require directly.
createCache
const createCache = require('level-content-cache')
const createCache = require('level-content-cache').createCache
No named export; the module exports a single function.

Initializes a content cache with LevelDB, a content-addressable store, and a getter that fetches URLs via request.

const levelup = require('levelup'); const CAS = require('content-addressable-store'); const ContentCache = require('level-content-cache'); const request = require('request'); const db = levelup('./mydb'); const cas = CAS('./mycas'); const get = ContentCache(db, cas, { getter: function (key, meta, cb) { request(key, function (err, res, body) { if (err) return cb(err); cb(null, body); }); } }); get('http://example.com/data.json', function (err, value) { if (err) console.error(err); else console.log(value); });
Debug
Known issues
gotchaThe package does not handle getter errors that return falsy values properly; ensure cb(err) always passes an Error object.
fix
Wrap error responses in `new Error()` before calling cb.
affects: <=1.3.3
deprecatedThe package uses the deprecated `request` library in examples; not a direct issue but encourages outdated patterns.
fix
Replace `request` with a modern HTTP client like `node-fetch` or `axios` in custom getter.
affects: *
gotchaThe meta object passed to getter is mutable; changes to meta inside getter may affect caching behavior unexpectedly.
fix
Treat meta as read-only or clone before modification.
affects: *
breakingThe cache key is derived from the first argument passed to get; must be a string. Passing numbers or objects may break silently.
fix
Always convert keys to strings before calling get.
affects: <=1.3.3
Errors
Common errors & fixes
Error: Cannot find module 'level-content-cache'
Package not installed or imported incorrectly.
fix
Run `npm install level-content-cache` and use `require('level-content-cache')`.
TypeError: get is not a function
The required module is not a function because the constructor was called without `new` or with wrong arguments.
fix
Ensure you call `ContentCache(db, cas, opts)` and assign the result to a variable.
Error: getter is not a function
Missing or invalid getter option in the options object.
fix
Provide a `getter` function with signature `function(key, meta, cb)`.
Upgrade
Version history
1.3.3latest on npm
Audit
Dependencies
leveluprequiredRequired for the LevelDB database instance passed to the cache constructor.
content-addressable-storerequiredRequired for the content-addressable store instance passed to the cache constructor.
requestoptionalUsed in example for fetching remote resources; not a hard dependency but commonly paired.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
level-content-cache — npm install level-content-cache · libregistry