Registry / storage / flru
library1.0.2jsnpmunverified

A tiny (215B) and fast Least Recently Used (LRU) cache for JavaScript. Stable version 1.0.2, last updated in 2019. No active release cadence; essentially stable and minimal. Key differentiators: extremely small size (215B), high performance with a two-cache internal architecture that trades memory for speed, supports ESM, CJS, and UMD formats, and includes TypeScript types. Compared to alternatives like lru-cache or tiny-lru, flru is much smaller and faster for typical operations but uses 2n memory and has a simpler API.

npm install flru
INSTALL
IMPORT
SIG · FLRU
F
flru
storagejavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flru
import flru from 'flru'
import { flru } from 'flru'
Default export only; named import will not work. CJS: const flru = require('flru').
flru
const flru = require('flru')
const { flru } = require('flru')
CJS: flru is the default export, not a named export.
CacheType
import type { CacheType } from 'flru'
If you use TypeScript, you can import the CacheType interface. It is not required.

Creates an LRU cache with max 3 items, demonstrates set, get, has, eviction, and clear.

import flru from 'flru'; const cache = flru(3); // max 3 items cache.set('a', 1); cache.set('b', 2); cache.set('c', 3); cache.has('a'); // true cache.get('a'); // 1 cache.set('d', 4); // evicts oldest (b) cache.get('b'); // undefined cache.clear(); cache.has('a'); // false
Debug
Known issues
gotchaflru uses two internal caches (active and stale) and stores up to 2n items. Memory usage is roughly double the limit compared to single-cache LRU implementations.
fix
Consider memory implications when using with large limits.
affects: >=1.0.0
gotchaget() does NOT promote a key to the active cache if the key is in the stale cache; it returns the value but the key may be evicted later.
fix
Read the documentation on the two-cache architecture to understand eviction behavior.
affects: >=1.0.0
gotchaThe default max is 1, which is inefficient and likely not what you want. Always specify a max.
fix
Always pass a positive integer to flru().
affects: >=1.0.0
deprecatedThe package appears unmaintained since 2019. No known security issues, but consider alternatives for long-term support.
fix
Evaluate lru-cache or tiny-lru for active maintenance.
affects: 1.0.2
Errors
Common errors & fixes
import { flru } from 'flru'
Trying to import flru as a named export instead of default.
fix
Use import flru from 'flru'
const { flru } = require('flru')
CJS destructuring on a default export.
fix
Use const flru = require('flru')
flru is not a function
Using flru without calling it, e.g., assigning flru instead of flru(3).
fix
Call flru with a max number: const cache = flru(3)
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
22
Amazon
1
Resources
packageflru
flru — npm install flru · libregistry