0.1.8 • Published 6 years ago

persistent-cache-object v0.1.8

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

persistent-cache-object

A simple JSON auto persistent object using files.

example 1

const PersistentObject = require('persistent-cache-object');
const map = new PersistentObject('./map.db');
map['key'] = 'value';
map.close();

example 2

By default the persistent object will update the file every 5 seconds only if the object has changed since. This can be controlled or disabled when initializing the Object. flush() must be used to manually write to file.

const PersistentObject = require('persistent-cache-object');
const map = new PersistentObject('./map.db', null, {'disableInterval': true});
map['key'] = 'value';
map.flush();
map['key2'] = 'value2';
map.close();

example 3

The file update interval timer can also be set on initialization. This example sets the interval to 10s and disabling it later.

const PersistentObject = require('persistent-cache-object');
const map = new PersistentObject('./map.db', null, {interval: 10000});
map['key'] = 'value';
map.setInterval(-1);

example 4

Initialize persistent object with and existing object.

const PersistentObject = require('persistent-cache-object');
const map = new PersistentObject('./map.db', {'key':'value'});

example 5

Using locks to allow multiple node processes access the same object. N.B to be used with caution.

const PersistentObject = require('../src/persistent-cache-object');
const map = new PersistentObject('./map.db', null, {'disableInterval': true});

map.lock(() => {
	map.reload();
	map['aKey'] = 'aValue';
	map.flush();
	map.unlock();
});
0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago