node-cache-manager-fs-binary
Node Cache Manager store for Filesystem with binary data
The Filesystem store for the node-cache-manager module, storing binary data as separate files, returning them as readable streams or buffers.
This should be convenient for caching binary data and sending them as streams to a consumer, e.g. res.send()
.
The library caches on disk arbitrary data, but values of an object under the special key binary
is stored as separate files.
Node.js versions
Works with versions 4, 5 and iojs.
Installation
npm install cache-manager-fs-binary --save
Usage examples
Here are examples that demonstrate how to implement the Filesystem cache store.
Features
- limit maximum size on disk
- refill cache on startup (in case of application restart)
- returns binary data as buffers or readable streams (keys of the
binary
key) - can store buffers inside the single cache file (not keys of the
binary
key)
Single store
// node cachemanagervar cacheManager = ;// storage for the cachemanagervar fsStore = ;// initialize caching on diskvar diskCache = cacheManager; // ...var cacheKey = 'userImageWatermarked:' + userid + ':' + imageid;var ttl = 60 * 60 * 24 * 7; // in seconds // wrapper function, see more examples at node-cache-managerdiskCache
Options
options for store initialization
// default values // time to live in seconds optionsttl = 60; // path for cached files optionspath = 'cache/'; // prevent filling of the cache with the files from the cache-directory optionspreventfill = false; // callback fired after the initial cache filling is completed optionsfillcallback = null; // if true the main cache files will be zipped (not the binary ones) optionszip = false; // if true buffers not from binary key are returned from cache as buffers, // not objects optionsreviveBuffers = false; // if true, data in the binary key are returned as StreamReadable and // (**NB!**) the source object will also be changed. // You have to do the work for closing the files if you do not read them, // see example. optionsbinaryAsStream = false;
Tests
To run tests:
npm test
Code Coverage
To run Coverage:
npm run coverage
License
cache-manager-fs-binary is licensed under the MIT license.