Tiny & Fast LRU Implementation as possible.
- Fast: Ultra-high performance (See benchmark).
- Simple: The whole project is ~60 lines of code.
- Lightweight: The package weighs less than a megabyte, with zero dependencies.
hyperlru claim to be fast and simple as possible. There are a lot of LRU implementations, but most of them have a poor perfomance and they are hard to understand.
It's Inspired by the hashlru algorithm.
$ npm install hyperlru --save
const hyperlru = require('hyperlru')
const cache = hyperlru({max: 1000})
name | size | gzip | set | get1 | update | get2 | evict |
---|---|---|---|---|---|---|---|
lru-cache | 19.1 kB | 6.23 kB | 922 ops | 3030 ops | 2105 ops | 4082 ops | 917 ops |
modern-lru | 2.27 kB | 907 B | 813 ops | 1299 ops | 752 ops | 1515 ops | 629 ops |
mkc | 10.5 kB | 3.61 kB | 784 ops | 766 ops | 810 ops | 1149 ops | 697 ops |
lru_cache | 2.19 kB | 756 B | 6452 ops | 18182 ops | 14286 ops | 9524 ops | 3509 ops |
hashlru | 628 B | 332 B | 5263 ops | 6897 ops | 4545 ops | 7407 ops | 3922 ops |
tiny-lru | 4 kB | 1.64 kB | 3509 ops | 11765 ops | 15385 ops | 11765 ops | 2222 ops |
quick-lru | 1.23 kB | 489 B | 3279 ops | 2198 ops | 3226 ops | 2105 ops | 2778 ops |
lru | 6.07 kB | 1.86 kB | 2500 ops | 3846 ops | 3175 ops | 3226 ops | 976 ops |
hyperlru | 889 B | 395 B | 2299 ops | 25000 ops | 2410 ops | 22222 ops | 2439 ops |
lru-fast | 2.34 kB | 793 B | 1869 ops | 6897 ops | 4167 ops | 16667 ops | 3077 ops |
simple-lru-cache | 1.43 kB | 565 B | 1709 ops | 13333 ops | 5128 ops | 22222 ops | 3922 ops |
secondary-cache | 22.6 kB | 6.54 kB | 1695 ops | 2632 ops | 2667 ops | 5556 ops | 1408 ops |
See more at bench-lru.
Type: number
Default: 1000
Max of element to keep into the cache.
Set the value of the key and mark the key as most recently used.
It returns the value
.
Query the value of the key and mark the key as most recently used.
It returns the value of key if found; undefined
otherwise.
It retrieves all the keys currently in the cache.
Clear all the elements in the cache.
MIT © Kiko Beats.