Simplified LRU Cache based on Lucky.js
$ npm i x-lru --save
所有LRU模式的API都是相同的。
获取LRU的长度
添加LRU元素,新增的元素会插入到LRU的头部
获取元素,命中key的元素会移动至LRU的头部
获取LRU头部元素,但不会删除
- LRU-1
- LRU-2
- MultiQueue
- TwoQueues
'use strict';
const {LRU} = require('x-lru');
const lru = new LRU({maxSize: 100});
lru.set('one', 1);
console.log(lru.length); // 1
Lucky.js © Ricky 泽阳, Released under the MIT License.