https://github.com/shenfe/lru
♻️ LRU (Least Recently Used) cache.
https://github.com/shenfe/lru
cache lru lru-cache
Last synced: about 1 year ago
JSON representation
♻️ LRU (Least Recently Used) cache.
- Host: GitHub
- URL: https://github.com/shenfe/lru
- Owner: shenfe
- License: mit
- Created: 2018-02-07T15:52:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-15T03:14:36.000Z (almost 8 years ago)
- Last Synced: 2025-03-11T23:34:10.151Z (about 1 year ago)
- Topics: cache, lru, lru-cache
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
♻️ LRU (Least Recently Used) Cache.
* single file ✨
* browser✔
* Node.js✔
* dependencies
* babel
* polyfills
## Installation
```bash
$ npm install --save llrruu
```
## Usage
### import
```js
const LRU = require('llrruu');
```
### create
The module exported is both a constructor and a factory function. It accepts either a number or an object.
```js
const lru1 = new LRU(10);
const lru2 = LRU(10);
const lru3 = LRU({
maxSize: 10,
onEvict: (key, val) => console.log(`${key} is being kicked out, with its value `, val)
});
```
### api
```js
lru.set('a', 1); // will affect the order
lru.get('a'); // will affect the order
lru.val('a', 1);
lru.val('a');
lru.remove('a');
lru.keys();
lru.size();
lru.clear();
```
## Test
```bash
$ npm test
```
## License
MIT