npm.io
0.1.1 • Published 7 years ago

rl-store

Licence
MPL-2.0
Version
0.1.1
Deps
1
Size
9 kB
Vulns
0
Weekly
0

rl-store

A map which be limited size of storage for catching.

Rin&Len store.

const RlStroe = require('rl-store');

const store = new RlStroe(1000); // Limite the store only retain 1000 length of string.

// to test the key exist
'key0' in store.data
// or
store.has('key0')

// to set
store.data['key1'] = 'value1';
store.dispatch('set', {key: 'key1'});
// or
store.set('key1', 'value1')

// to get
let value1 = store.data['key2'];
store.dispatch('get', {key: 'key2'});
// or
store.get('key2')

// to remove a key maunally
store.delete('key1');

And, you can extend RLStore to get the event when store be called into get(), set() and delete().

const RlStroe = require('rl-store');

class MyRlStroe extends RlStroe {
    onGet(payload :any){
        console.log('got!');
        super.onGet(payload);
    }
}