memory-cache-stream
v1.2.0
Published
In-memory cache modeled after node_redis api with additional streaming support.
Downloads
88
Readme
memory-cache-stream
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.