README
x-lru
Simplified LRU Cache based on Lucky.js
Install
$ npm i x-lru --save
API
所有LRU模式的API都是相同的。
length: number
1、获取LRU的长度
set(key: string, value: any): void
2、添加LRU元素,新增的元素会插入到LRU的头部
get(key: string): any
3、获取元素,命中key的元素会移动至LRU的头部
peek(): {key: string, value: any}
4、获取LRU头部元素,但不会删除
Features
- 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.