Skip to content

rickyes/x-lru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x-lru

Simplified LRU Cache based on Lucky.js

Travis Node Version npm Codecov

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

  • 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.

Releases

No releases published

Packages

No packages published