Registry / storage / cache-chunk-store

cache-chunk-store

JSON →
library3.2.2jsnpmunverified

In-memory LRU cache for abstract-chunk-store compliant stores. Version 3.2.2 is the latest stable release, with a maintenance status and low release cadence. It wraps any abstract-chunk-store implementation (e.g., fs-chunk-store) to cache get() results using the lru package, reducing repeated I/O. Differentiators: minimal API, transparent caching, passes through options to lru (e.g., max size). Commonly used in BitTorrent clients and other peer-to-peer applications.

npm install cache-chunk-store
INSTALL
IMPORT
SIG · CACHE-CHUNK-STORE
C
cache-chunk-store
storagejavascriptv3.2.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.

CacheChunkStore
✓ const CacheChunkStore = require('cache-chunk-store')
✗ import CacheChunkStore from 'cache-chunk-store'
This package uses CommonJS; ESM import is not supported unless using a bundler that handles CJS interop.
CacheChunkStore
✓ import CacheChunkStore from 'cache-chunk-store'
✗ import { CacheChunkStore } from 'cache-chunk-store'
Default export only, not a named export.
CacheChunkStore
✓ const { CacheChunkStore } = require('cache-chunk-store')
✗ const { CacheChunkStore: MyCache } = require('cache-chunk-store')
Destructured require works but is redundant; the default is the class itself.

Creates a cached chunk store using fs-chunk-store with LRU max 100, puts a chunk, and retrieves it twice (second is cached).

const CacheChunkStore = require('cache-chunk-store') const FSChunkStore = require('fs-chunk-store') const store = new CacheChunkStore(new FSChunkStore(10), { max: 100 }) store.put(0, Buffer.from('abc'), (err) => { if (err) throw err store.get(0, (err, data) => { if (err) throw err console.log(data.toString()) // 'abc' // Cached call: store.get(0, (err, data) => { if (err) throw err console.log(data.toString()) }) }) })
Debug
Known issues
gotchaThe store passed to CacheChunkStore must be a valid abstract-chunk-store instance; otherwise behavior is undefined.
fix
Ensure the inner store implements all required methods (put, get, close, destroy).
affects: >=1.0.0
deprecatedThe lru package has been deprecated; caching behavior may not be optimal.
fix
Consider using an alternative like lru-cache or wrapping manually.
affects: >=3.0.0
breakingIn version 2.x, the constructor accepted options as first argument; in 3.x it accepts the store first.
fix
Upgrade to 3.x and swap arguments: new CacheChunkStore(store, opts).
affects: >=2.0.0 <3.0.0
gotchaBuffer is not imported; uses global Buffer which may not exist in newer Node versions (deprecated).
fix
Use Uint8Array or polyfill Buffer; or use a version that imports Buffer.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: store.get is not a function
Passed a store that is not abstract-chunk-store compliant.
fix
Ensure the store implements get, put, close, and destroy methods.
Error: The first argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.
Passed a non-Buffer value to put() (e.g., a number).
fix
Use Buffer.from() to pass buffers.
Upgrade
Version history
3.2.2latest on npm
Audit
Dependencies
abstract-chunk-storerequiredpeer dependency - store interface must be compatible
lrurequiredLRU cache implementation
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
cache-chunk-store — npm install cache-chunk-store · libregistry