Registry / storage / streaming-cache

streaming-cache

JSON →
library0.5.5jsnpmunverified

A Node.js library that caches and replays streams using an LRU cache, enabling immediate delivery of streaming data even while the source stream is still being written. Current stable version is 0.5.5, which is likely the last release (no updates since 2019). It focuses on low-latency reuse of slow streams like S3 downloads or database queries, using a fixed-size LRU cache from the lru-cache package. Its key differentiator is the ability to replay unfinished streams, unlike caching complete files.

npm install streaming-cache
INSTALL
IMPORT
SIG · STREAMING-CACHE
S
streaming-cache
storagejavascriptv0.5.5
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
const Cache = require('streaming-cache');
import Cache from 'streaming-cache';
Package uses CommonJS only; no ESM exports.
Cache
import Cache from 'streaming-cache';
import { Cache } from 'streaming-cache';
Default import is correct with ESM module resolution but package is CJS.

Demonstrates creating a cache, writing a stream into it, then retrieving and piping it to a different output asynchronously.

const Cache = require('streaming-cache'); const fs = require('fs'); const cache = new Cache(); const readStream = fs.createReadStream('input.txt'); const writeStream1 = fs.createWriteStream('output1.txt'); const writeStream2 = fs.createWriteStream('output2.txt'); // Pipe source into cache readStream.pipe(cache.set('myKey')); // Later, retrieve the same stream and pipe to a different output setTimeout(() => { const cachedStream = cache.get('myKey'); if (cachedStream) { cachedStream.pipe(writeStream2); } }, 500); // Alternative: pipe directly on set() // cache.set('myKey2').pipe(writeStream1);
Debug
Known issues
gotchaCache.get() returns the stream only once; subsequent calls return undefined.
fix
If you need multiple consumers, pipe the cached stream to a PassThrough for each consumer, or use set() again.
affects: >=0.0.0
gotchaThe LRU cache evicts entries if the cache is full, potentially losing active streams.
fix
Ensure cache size is sufficient for your workload; consider using an unbounded cache for critical streams.
affects: >=0.0.0
gotchaset() returns a Duplex stream that must be properly ended to avoid memory leaks.
fix
Always pipe or end the writable side of the Duplex stream returned by set().
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: cache.get is not a function
Importing the module incorrectly or forgetting to create a Cache instance.
fix
Use: const Cache = require('streaming-cache'); const cache = new Cache(); cache.get('key');
TypeError: dest.on is not a function
Trying to pipe into a non-stream object or a null stream.
fix
Ensure the destination is a writable stream (e.g., fs.createWriteStream or through2).
Upgrade
Version history
0.5.5latest on npm
Audit
Dependencies
lru-cacherequiredUnderlying LRU cache for storing stream data
Agent activity
21 hits · last 30 days
node
18
Amazon
1
Resources
streaming-cache — npm install streaming-cache · libregistry