
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
an-lru-cache
Advanced tools
A simple LRU Cache, a Map that has a maximum number of entries and which discards the least recently used items first.
A simple LRU Cache, a Map that has a maximum number of entries and which discards the least recently used items first.
To install
$ npm install an-lru-cache
The API mirrors the builtin Map and WeakMap APIs but does not include iterators.
const { LruCache } = require('an-lru-cache')
const myCache = new LruCache() // Default capacity is 100
function foo(key, value) {
myCache.set(key, value)
// ...
return myCache.get(key)
}
function bar(key) {
if (myCache.has(key)) {
// ...
}
myCache.delete(key)
}
.set(key, value)Associates value with key so that .get(key) returns value
until a subsequent .set or .delete with the same key or
eviction.
.get(key, fallbackValue=undefined)Returns the value associated with key, or the fallbackValue if supplied.
Gets may return the fallbackValue even if there was a value associated with key if that entry was evicted to ensure that the number of entries did not exceed the maximum allowed.
.delete(key, fallbackValue=undefined)Deletes any entry for the given key returning the previously associated value if present or fallbackValue otherwise.
.has(key)True iff there is a value associated with key.
FAQs
A simple LRU Cache, a Map that has a maximum number of entries and which discards the least recently used items first.
We found that an-lru-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.