0.0.2 • Published 6 years ago
node-json-cache v0.0.2
node-json-cache
Use a json file as a cache.
Usage
import jsonCache from 'node-json-cache';
cache = jsonCache('.cache/filetocache.json');
// set an item
cache.setItem('key', 'value'); // 'value'
// get an item
cache.getItem('key'); // 'value'
// gets entire cache
cache.get(); // { key: 'value' }
// overwrite cache
cache.set({ hello: 'world' }); // { hello: 'world' }
// synchronously saves the cache
cache.save();
// clears the cache
cache.clear();
Options
const cache = jsonCache(filename[, options]);
filename
- path to cache fileoptions
- optionaloptions
.out
- optional, output operations to console, defaults tofalse
options
.wait
- optional, debounce time on operations, defaults to1000
options
.ejectable
- optional, save on exit/error, defaults tofalse
filesystem perfomance
Storage operations are batched. Storage is persisted on exit.
See also
Inspired by [Node LocalCache(https://github.com/glebmachine/node-localcache), With notable changes:
- explicity operate with a file, no
skipFileCachig
- allow setting of
undefined
as a value - allow getting and setting of the entire file
- async file saving by default
- more settings