Skip to content

vicanso/lru-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lru-store

A lru store for browser. It is better to use with store

Build Status Coverage Status npm Github Releases

Installation

$ npm install lru-store

API

constructor

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 is MemoryStore. 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

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

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

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');

keys

List all key of the store

const LRUStore = require('lru-store');
const store = new LRUStore({
  namespace: 'my-cache',
  max: 10,
});
const keys = store.keys();

clearAll

Clear all data from store

const LRUStore = require('lru-store');
const store = new LRUStore({
  namespace: 'my-cache',
  max: 10,
});
store.clearAll();

on

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);

License

MIT

Releases

No releases published

Packages

No packages published