A lru store for browser. It is better to use with store
$ npm install lru-store
The LRU-Store extends EventEmitter
-
options
-
options.namespace
The namespace for store -
options.max
The limit of store
-
-
store
The store client for lru, default isMemoryStore
. It's better to use store.
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
store.set('tree', {
vip: false,
amount: 10,
});
const info = store.get('tree');
Set the value to store
-
key
The key of value -
value
The value to store
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
store.set('tree', {
vip: false,
amount: 10,
});
Get the value from store
key
The key of value
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
const info = store.get('tree');
Remove the value from store
key
The key of value
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
store.remove('tree');
List all key of the store
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
const keys = store.keys();
Clear all data from store
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
store.clearAll();
Adds the listener function for event
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
store.on('update', console.info);
store.on('add', console.info);
store.on('remove', console.info);
store.on('hit', console.info);
MIT