x-lru
v0.0.2
Published
Simplified LRU Cache based on HashMap
Downloads
1
Readme
x-lru
Simplified LRU Cache based on Lucky.js
Install
$ npm i x-lru --save
API
所有LRU模式的API都是相同的。
1、length: number
获取LRU的长度
2、set(key: string, value: any): void
添加LRU元素,新增的元素会插入到LRU的头部
3、get(key: string): any
获取元素,命中key的元素会移动至LRU的头部
4、peek(): {key: string, value: any}
获取LRU头部元素,但不会删除
Features
- [x] LRU-1
- [ ] LRU-2
- [ ] MultiQueue
- [ ] TwoQueues
Example
'use strict';
const {LRU} = require('x-lru');
const lru = new LRU({maxSize: 100});
lru.set('one', 1);
console.log(lru.length); // 1
Author
Lucky.js © Ricky 泽阳, Released under the MIT License.