https://github.com/dtikhonov/mere-lru
Simple LRU for NodeJS
https://github.com/dtikhonov/mere-lru
javascript lru lru-cache nodejs
Last synced: 2 months ago
JSON representation
Simple LRU for NodeJS
- Host: GitHub
- URL: https://github.com/dtikhonov/mere-lru
- Owner: dtikhonov
- License: mit
- Created: 2021-08-02T00:58:57.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-02T01:04:46.000Z (almost 4 years ago)
- Last Synced: 2025-03-10T13:43:01.373Z (3 months ago)
- Topics: javascript, lru, lru-cache, nodejs
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mere-lru
A simple LRU for NodeJS## Introduction
This library implements an LRU Cache. It has only three methods: `get()`, `set()`, and `has()` and possesses the following traits:
- simplicity
- correctness
- uses [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) rather than `Object`.The reason I wrote it is that, at the time of this writing, I could not find a library that would satisfy all three requirements above.
## Usage
```javascript
// Import the class
const MereLRU = require('mere-lru');// Insert stuff
const cache = new MereLRU(100);
cache.set('key', 'value');
const v = cache.get('key'); // -> 'value'// Insert more elements
for (let i = 0; i < 100; ++i)
cache.set('key' + i, 'foo');// The first one is now gone:
cache.has('key'); // -> false
```## References
A good collection of related modules is here:
https://github.com/dominictarr/bench-lru(But take the benchmark results on that page with a barrel of salt.)