Socket
Socket
Sign inDemoInstall

lru-cache

Package Overview
Dependencies
0
Maintainers
1
Versions
134
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.4 to 2.1.0

13

lib/lru-cache.js

@@ -40,2 +40,4 @@ ;(function () { // closure for web browsers

var allowStale = options.stale || false
var maxAge = options.maxAge || null

@@ -147,2 +149,11 @@

this.has = function (key) {
if (!hOP(cache, key)) return false
var hit = cache[key]
if (maxAge && (Date.now() - hit.now > maxAge)) {
return false
}
return true
}
this.get = function (key) {

@@ -153,3 +164,3 @@ if (!hOP(cache, key)) return

this.del(key)
return
return allowStale ? hit.value : undefined
}

@@ -156,0 +167,0 @@ delete lruList[hit.lu]

2

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

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

@@ -268,1 +268,35 @@ var test = require("tap").test

})
test("has()", function(t) {
var cache = new LRU({
max: 1,
maxAge: 10
})
cache.set('foo', 'bar')
t.equal(cache.has('foo'), true)
cache.set('blu', 'baz')
t.equal(cache.has('foo'), false)
t.equal(cache.has('blu'), true)
setTimeout(function() {
t.equal(cache.has('blu'), false)
t.end()
}, 15)
})
test("stale", function(t) {
var cache = new LRU({
maxAge: 10,
stale: true
})
cache.set('foo', 'bar')
t.equal(cache.get('foo'), 'bar')
t.equal(cache.has('foo'), true)
setTimeout(function() {
t.equal(cache.has('foo'), false)
t.equal(cache.get('foo'), 'bar')
t.equal(cache.get('foo'), undefined)
t.end()
}, 15)
})
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc