New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

streaming-cache

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streaming-cache

Cache and replay NodeJS streams

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
56
decreased by-30.86%
Maintainers
1
Weekly downloads
 
Created
Source

Circle CI

Streaming Cache

Cache, queue and distribute streams immediately. Streams can be replayed immediately, even if the source is not finished.

Usefull for caching (slow) streaming connections, such as S3 requests or complex database queries.

We use it to stream data into the cache and make any waiting connections for the same data queue up until the data is in the cache.

If there are for example 3 requests for a certain file in close succession, then we can pipe the result for the first request into the cache. The 2 other requests will receive a stream which will start when the first one is finished.

Installation

npm i streaming-cache --save

Quick example


var Cache = require('../index.js');
var cache = new Cache();
var fs = require('fs');

var readstream = fs.createReadStream('readme.md');
var writestream = fs.createWriteStream('test2.txt');

readstream.pipe(cache.set('a'));

setTimeout(function(){
  writestream2.write('written from cache\n\n');
  cache.get('a').pipe(writestream);
 }, 200);

API

set(key)

returns a transform stream that can be piped to

fileStream.pipe(cache.set('key')).pipe(res);
get(key):ReadableStream
var cached = cache.get('key');
if(cached){
	cached.pipe(res);
}
setData(key, data)

A set data synchronously to stream at a later moment

getData

Get data with a callback.

cache.getData('key', function(err, data){
	if(err){ 
	  //handle error
	}
	// do something with data
}));
setMetadata(key, data)

Set metadata for a stream to be used later.

getMetadata(key, data)

Get metadata

exists(key)

returns true or false if a key exists.

Keywords

FAQs

Package last updated on 23 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc