Gathering detailed insights and metrics for flru
Gathering detailed insights and metrics for flru
Gathering detailed insights and metrics for flru
Gathering detailed insights and metrics for flru
npm install flru
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
321 Stars
19 Commits
4 Forks
5 Watchers
1 Branches
3 Contributors
Updated on Feb 11, 2025
Latest Version
1.0.2
Package Id
flru@1.0.2
Unpacked Size
8.73 kB
Size
3.79 kB
File Count
7
NPM Version
6.4.1
Node Version
10.13.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A tiny (215B) and fast Least Recently Used (LRU) cache
Internally, two caches are kept. This is because it's far more performant to swap (and maintain) dictionaries than it is to delete
/purge keys on every read/write interaction. Because of this, flru
will store 2n
items in memory, where n
is the max
limit. In practice, this means that with max=3
and items (a, b, c)
already written, writing a d
value will not automatically purge the a
key. Instead, a
can be retrieved, which would move it to the "active" cache. It's only when this "active" half exceeds the max
that the "stale" half is purged.
See Usage for a visual explanation~!
This implementation is optimized for all-around performance – reads, writes, updates, and evictions.
This module is available in three formats:
dist/flru.mjs
dist/flru.js
dist/flru.min.js
$ npm install --save flru
1// Legend: 2// S => the stale cache 3// A => the active cache 4 5const flru = require('flru'); 6 7let cache = flru(3); // A=[] S=[] 8 9cache.set('a', 1); // A=[a] S=[] 10cache.set('b', 2); // A=[a,b] S=[] 11cache.set('b', 9); // A=[a,b] S=[] 12cache.set('c', 3); // A=[a,b,c] S=[] 13 14cache.has('a'); //=> true 15 16cache.set('d', 4); // A=[d] S=[a,b,c] 17cache.get('a'); // A=[d,a] S=[a,b,c] 18cache.set('e', 5); // A=[d,a,e] S=[a,b,c] 19cache.get('a'); // A=[d,a,e] S=[a,b,c] 20cache.get('c'); // A=[c] S=[d,a,e] 21 22cache.has('c'); //=> true 23cache.has('b'); //=> false 24cache.has('a'); //=> true 25 26cache.clear(); // A=[] S=[]
return Object
Initialize a new flru
cache instance.
Required: true
Type: Number
Default: 1
The maximum number of items to maintain – must be a positive, non-zero integer!
Important: The default value is pointless and will result in excessive computation. It's there only to avoid memory leak!
Return: Boolean
Check if the cache has the given key.
Type: String
The key name to check.
Return: Mixed
Get the assigned value for a given key. Will return undefined
if the cache has evicted key
or never contained it.
Type: String
The item's unique name / identifier.
Return: undefined
Persist an item to the cache by a given key
name.
Type: String
The item's unique name / identifier.
Type: Mixed
The item's value to be cached.
Return: undefined
Reset the cache(s) and counter.
Type: Boolean
Default: false
When true
, preserves the stale/outgoing cache.
Important: This is used internally & generally should be ignored!
You can find benchmarks in the bench
directory. They are setup to run one library at a time so that there's no cross-contamination of memory management or Node's runtime caching.
set
– writing values into new keysupdate
– updating values into existing keysevict
– writing 2 * limit
keys to the cache, forcing evictionResults below are with Node v10.13.0
# set()
flru x 45,261 ops/sec ±1.63% (94 runs sampled)
lru-cache x 14,240 ops/sec ±5.70% (85 runs sampled)
tmp-cache x 8,229 ops/sec ±3.06% (83 runs sampled)
tiny-lru x 24,415 ops/sec ±2.48% (91 runs sampled)
# get()
flru x 78,585 ops/sec ±1.70% (98 runs sampled)
lru-cache x 27,409 ops/sec ±2.64% (93 runs sampled)
tmp-cache x 6,229 ops/sec ±1.06% (87 runs sampled)
tiny-lru x 20,313 ops/sec ±2.01% (96 runs sampled)
# has()
flru x 79,843 ops/sec ±1.35% (97 runs sampled)
lru-cache x 31,354 ops/sec ±2.87% (90 runs sampled)
tmp-cache x 813,828 ops/sec ±64.67% (95 runs sampled)
tiny-lru x 128,250 ops/sec ±3.73% (93 runs sampled)
# update()
flru x 44,885 ops/sec ±1.86% (95 runs sampled)
lru-cache x 15,616 ops/sec ±2.46% (94 runs sampled)
tmp-cache x 8,529 ops/sec ±0.85% (87 runs sampled)
tiny-lru x 23,060 ops/sec ±2.72% (93 runs sampled)
# evict()
flru x 8,258 ops/sec ±1.48% (88 runs sampled)
lru-cache x 1,492 ops/sec ±2.60% (77 runs sampled)
tmp-cache x 836 ops/sec ±0.59% (95 runs sampled)
tiny-lru x 2,626 ops/sec ±2.61% (81 runs sampled)
tiny-lru
- Same as tmp-cache
but significantly faster.MIT © Luke Edwards
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/19 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More