Socket
Socket
Sign inDemoInstall

lru-cache

Package Overview
Dependencies
Maintainers
1
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lru-cache - npm Package Compare versions

Comparing version 2.2.4 to 2.3.0

25

lib/lru-cache.js

@@ -196,12 +196,27 @@ ;(function () { // closure for web browsers

this.get = function (key) {
if (!hOP(cache, key)) return
return get(key, true)
}
this.peek = function (key) {
return get(key, false)
}
function get (key, doUse) {
var hit = cache[key]
if (maxAge && (Date.now() - hit.now > maxAge)) {
this.del(key)
return allowStale ? hit.value : undefined
if (hit) {
if (maxAge && (Date.now() - hit.now > maxAge)) {
del(hit)
if (!allowStale) hit = undefined
} else {
if (doUse) use(hit)
}
if (hit) hit = hit.value
}
return hit
}
function use (hit) {
shiftLU(hit)
hit.lu = mru ++
lruList[hit.lu] = hit
return hit.value
}

@@ -208,0 +223,0 @@

2

package.json
{
"name": "lru-cache",
"description": "A cache object that deletes the least-recently-used items.",
"version": "2.2.4",
"version": "2.3.0",
"author": "Isaac Z. Schlueter <i@izs.me>",

@@ -6,0 +6,0 @@ "scripts": {

@@ -63,2 +63,11 @@ # lru cache

* `peek(key)`
Returns the key value (or `undefined` if not found) without
updating the "recently used"-ness of the key.
(If you find yourself using this a lot, you *might* be using the
wrong sort of data structure, but there are some use cases where
it's handy.)
* `del(key)`

@@ -65,0 +74,0 @@

@@ -318,1 +318,13 @@ var test = require("tap").test

})
test("least recently set w/ peek", function (t) {
var cache = new LRU(2)
cache.set("a", "A")
cache.set("b", "B")
t.equal(cache.peek("a"), "A")
cache.set("c", "C")
t.equal(cache.get("c"), "C")
t.equal(cache.get("b"), "B")
t.equal(cache.get("a"), undefined)
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc