A Simple Json Cache
auto save json data to disk/localStorage when object change. it support nodejs and web.
Build Setup
npm install simple-json-cache --save
cd node_modules/simple-json-cache
npm run test
API
SimpleJsonCache
- newObject(object,name)
- object.save()
- object.read()
Usage
NodeJS
const SimpleJsonCache = require('simple-json-cache')
const DiskCache = require('simple-json-cache/cache-engine/disk-cache.js')
var sjc = new SimpleJsonCache(new DiskCache({
dir: 'cache',
debug: true
}), {
saveDelay: 1000,
debug: true
})
var data = sjc.newObject({a:'a',b:[1,2,3],c:{c1:10}},'data')
data.b.push(data.c.c1)
data.c.c1++
data.newProto='newProto'
data.save()
Web(Vue)
const SimpleJsonCache = require('simple-json-cache')
const StorageCache = require('simple-json-cache/cache-engine/storage-cache.js')
Vue.prototype.sjc = new SimpleJsonCache(new StorageCache({
prefix: 'jsc_',
debug: true
}), {
saveDelay: 1000,
debug: true
})
var config = this.sjc.newObject({a:'aaa',b:[1,2,3]},'config')
config.a='sdsasa'
config.b[1]++
config.newProto='newProto'
config.save()