A small Lib to Hold a JSON-File in Memory Cache
Just run npm install lib-jsoncache
The Usage is simple, the config is extensive :-)
const JSONCache = require('lib-jsoncache')
let jc = new JSONCache(config)
jc.load()
This is an Array of Objects from the JSON-File
jc.data
You may, e.g. jc.data.push({})
jc.save()
Every x Seconds (30 seconds or set in Config) the file may autosave using a simple interval.
To Start this use:
jc.startAutoSave()
To Stop it:
jc.stopAutoSave()
There are a lot of config parameters to give.
Just see config.sample.json for a full example of all options.
- file: Name of the JSON-File to Load from / Save to
- saveInterval: How often to autosave the file (in milliseconds). Default is 30 seconds
- autoload: Set to True to autoload the File on init. otherwise you have to call .load()
- autosave: Set to True to autosave the File in intervals. You may also call .save() whenever you want to save
To Test you may install the dev-dependencies.
Then just run npm run test