memory-cache-stream

1.2.0 • Public • Published

memory-cache-stream

NPM Version NPM Downloads Build Status Test Coverage

In-memory cache implementing a subset of the node-redis API - specifically the get, set, setex, exists, del, flushall, and ttl commands. Like node_redis, all commands can take an optional callback as the final argument.

This cache isn't really intended for production scenarios, but is suitable for use in place of node_redis for development environments and unit tests.

In addition to the subset of the built-in Redis commands, there are 3 additional functions: readStream, writeStream, and writeThrough that are used to stream data into and out of the cache. Although these are purely for backwards API compatibility since the cached strings are already in memory.

For the real Redis, checkout the redis-streams package augments RedisClient with these same functions.

Installation

npm install memory-cache-stream 

Usage

var memoryCache = require('memory-cache-stream');
 
// Set with ttl of 1 minute
memoryCache.setex(key, 60, 'some string to cache');
 
// Get using a callback
memoryCache.get(key, function(err, data) {
    console.log(data);
});
 
// Pipe out of the cache
memoryCache.readStream(key)
    .pipe(process.stdout);
 
// Pipe into a cache
fs.createReadStream('file.txt')
    .pipe(memoryCache.writeStream(key, 60))
    .on('finish', done);
 
// Pipe into the cache and through to stdout
fs.createReadStream('file.txt')
    .pipe(memoryCache.writeThrough(key, 60))
    .pipe(process.stdout);

See the unit tests for additional examples.

Package Sidebar

Install

npm i memory-cache-stream

Weekly Downloads

12

Version

1.2.0

License

MIT

Last publish

Collaborators

  • dvonlehman