0.0.2 • Published 6 years ago

node-json-cache v0.0.2

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

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 file
  • options - optional
  • options.out - optional, output operations to console, defaults to false
  • options.wait - optional, debounce time on operations, defaults to 1000
  • options.ejectable - optional, save on exit/error, defaults to false

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