Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including memory-cache-stream with all npm packages installed. Try it out:

var memoryCacheStream = require("memory-cache-stream")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

memory-cache-stream v1.2.0

In-memory cache modeled after node_redis api with additional streaming support.

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.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free