https://github.com/vicanso/lru-store
A lru store for browser
https://github.com/vicanso/lru-store
localstorage lru-store lua store
Last synced: about 2 months ago
JSON representation
A lru store for browser
- Host: GitHub
- URL: https://github.com/vicanso/lru-store
- Owner: vicanso
- License: mit
- Created: 2017-04-05T13:52:47.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-16T13:07:34.000Z (over 8 years ago)
- Last Synced: 2025-10-02T15:57:39.593Z (9 months ago)
- Topics: localstorage, lru-store, lua, store
- Language: JavaScript
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lru-store
A lru store for browser. It is better to use with [store](https://github.com/marcuswestin/store.js)
[](https://travis-ci.org/vicanso/lru-store)
[](https://coveralls.io/r/vicanso/lru-store?branch=master)
[](https://www.npmjs.org/package/lru-store)
[](https://github.com/vicanso/lru-store)
## Installation
```bash
$ 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](https://github.com/marcuswestin/store.js).
```js
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
```js
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
```js
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
```js
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
store.remove('tree');
```
### keys
List all key of the store
```js
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
const keys = store.keys();
```
### clearAll
Clear all data from store
```js
const LRUStore = require('lru-store');
const store = new LRUStore({
namespace: 'my-cache',
max: 10,
});
store.clearAll();
```
### on
Adds the listener function for event
```js
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