# streaming-cache

> Cache and replay NodeJS streams

Latest version **0.5.5** (published 2018-09-30) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install streaming-cache
pnpm add streaming-cache
yarn add streaming-cache
bun add streaming-cache
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.5 |
| Published | 2018-09-30 |
| First published | 2015-11-18 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 5.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Laurent Zuijdwijk |
| Maintainers | laurent.zuijdwijk |
| Keywords | cache, streams, queue |

## Links

- npm: https://www.npmjs.com/package/streaming-cache
- Repository: https://github.com/LaurentZuijdwijk/streaming-cache
- Homepage: https://github.com/LaurentZuijdwijk/streaming-cache#readme
- Issues: https://github.com/LaurentZuijdwijk/streaming-cache/issues
- npm.io page: https://npm.io/package/streaming-cache

## Dependencies (3)

- [lru-cache](https://npm.io/package/lru-cache.md) ^2.7.0
- [linkedlist](https://npm.io/package/linkedlist.md) ^1.0.1
- [lodash.assign](https://npm.io/package/lodash.assign.md) ^4.0.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.5.5 (latest) — 2018-09-30
- 0.5.4 — 2018-07-13
- 0.5.1 — 2017-03-25
- 0.5.0 — 2016-01-29
- 0.4.1 — 2016-01-07
- 0.4.0 — 2016-01-07
- 0.3.2 — 2015-12-23
- 0.3.1 — 2015-12-23
- 0.3.0 — 2015-12-23
- 0.2.1 — 2015-12-15
- 0.2.0 — 2015-12-15
- 0.1.7 — 2015-11-19
- 0.1.6 — 2015-11-19
- 0.1.5 — 2015-11-19
- 0.1.4 — 2015-11-19
- … 2 more at https://npm.io/package/streaming-cache/versions

## README

[![Circle CI](https://circleci.com/gh/LaurentZuijdwijk/streaming-cache/tree/master.svg?style=svg)](https://circleci.com/gh/LaurentZuijdwijk/streaming-cache/tree/master)

Streaming Cache
===============

Speed up your services.

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

Uses a fixed size LRU-cache in the background.

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

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 even before the first one is finished.

Performance
-----------

Serving from this cache is extremely fast. On my local machine I get 2.5GB per second for a single process on localhost using AB. (4th gen i7).

Installation
------------

```npm i streaming-cache --save```

Quick example
-------------

```javascript

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

var inputStream = fs.createReadStream('readme.md');
var outputStream = fs.createWriteStream('test2.txt');

inputStream.pipe(cache.set('myKey'));

setTimeout(function(){
  outputStream.write('written from cache\n\n');
  cache.get('myKey').pipe(outputStream);
 }, 200);

```

Options
-------

For a list of options see: https://www.npmjs.com/package/lru-cache


API
---

##### set(key)
returns a Duplex stream
```
fileStream.pipe(cache.set('key')).pipe(res);
```


##### get(key) => ReadableStream

```javascript
var cached = cache.get('key');
if(cached){
	cached.pipe(res);
}
```


#### setData(key, data) => WriteableStream
A set data synchronously to stream at a later moment

#### getData
Get data with a callback.

```javascript
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.

---
_Source: https://npm.io/package/streaming-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
