boomerangCache is a client side caching library based on localStorage.
Npm:
npm install boomerang-cache
Bower:
bower install boomerang-cache
https://giraysam.github.io/boomerang-cache
- create
- check
- set
- get
- getAll
- length
- remove
- clear
Creates a new bucket.
bucket
(String)options
(Object)storage
: (local | session)encrypt
: (true | false)
var boomerang = BoomerangCache.create('bucket1', {storage: 'local', encrypt: true});
Set a key to a particular value or a hash object (Object or Array) under a hash key.
key
(String)value
(String, Number, Object, Array)seconds
(Number) - optional
These values will never expire and will only be removed when you (or the browser) removes them.
boomerang.set('stringData', 'Hello World');
boomerang.set('numberData', 12345);
boomerang.set('objectData', {value: 'Hello World'});
boomerang.set('arrayData', [{value: 'Hello World'}, {value: 'Hello Boomerang'}]);
After 3 seconds this will return null.
var seconds = 3;
boomerang.set('key', 'Hello World', seconds);
Returns the saved value for given key. If value is null or undefined it returns a default value.
key
(String)defaultValue
(String, Number, Object, Array)
boomerang.get('key', 'Hello World'); // If value is null returns Hello World.
Returns all saved values.
boomerang.getAll();
// {key1: 'value1'}, {key2: 'value2'}
Returns all values count.
boomerang.length();
// returns 2
Remove a key from storage
key
(String)
boomerang.remove('key');
Empties storage
boomerang.clear();