npm

Need private packages and team management tools?Check out npm Orgs. »

lru-store

1.0.2 • Public • Published

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

install

npm i lru-store

Downloadsweekly downloads

3

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability