Socket
Socket
Sign inDemoInstall

lru-cache

Package Overview
Dependencies
0
Maintainers
1
Versions
135
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.4 to 1.0.5

.gitignore

95

lib/lru-cache.js

@@ -0,3 +1,9 @@

;(function () { // closure for web browsers
module.exports = LRUCache
if (module) {
module.exports = LRUCache
} else {
// just set the global for non-node platforms.
;(function () { return this })().LRUCache = LRUCache
}

@@ -30,3 +36,5 @@ function hOP (obj, key) {

})
this.maxLength = maxLength
Object.defineProperty(this, "length",

@@ -37,2 +45,10 @@ { get : function () { return length }

this.reset = function () {
cache = {}
lruList = {}
lru = 0
mru = 0
length = 0
}
this.set = function (key, value) {

@@ -49,2 +65,3 @@ if (hOP(cache, key)) {

}
this.get = function (key) {

@@ -59,2 +76,3 @@ if (!hOP(cache, key)) return undefined

}
this.del = function (key) {

@@ -68,2 +86,3 @@ if (!hOP(cache, key)) return undefined

}
function lruWalk () {

@@ -73,2 +92,3 @@ // lru has been deleted, hop up to the next hit.

}
function trim () {

@@ -86,73 +106,2 @@ if (length <= maxLength) return undefined

if (!process || !module || module !== process.mainModule) return undefined
var l = LRUCache(3)
, assert = require("assert")
l.set(1, 1)
l.set(2, 1)
l.set(3, 1)
l.set(4, 1)
l.set(5, 1)
l.set(6, 1)
assert.equal(l.get(1), undefined)
assert.equal(l.get(2), undefined)
assert.equal(l.get(3), undefined)
assert.equal(l.get(4), 1)
assert.equal(l.get(5), 1)
assert.equal(l.get(6), 1)
// now keep re-getting the 6 so it remains the most recently used.
// in this case, we'll have 6, 7, 8, 9, 10, 11, so the ending length = 5
l.set(7, 1)
l.get(6)
l.set(8, 1)
l.get(6)
l.set(9, 1)
l.get(6)
l.set(10, 1)
l.get(6)
l.set(11, 1)
assert.equal(l.length, 3)
assert.equal(l.get(4), undefined)
assert.equal(l.get(5), undefined)
assert.equal(l.get(6), 1)
assert.equal(l.get(7), undefined)
assert.equal(l.get(8), undefined)
assert.equal(l.get(9), undefined)
assert.equal(l.get(10), 1)
assert.equal(l.get(11), 1)
// test changing the maxLength, verify that the LRU items get dropped.
l.maxLength = 100
for (var i = 0; i < 100; i ++) l.set(i, i)
assert.equal(l.length, 100)
for (var i = 0; i < 100; i ++) {
assert.equal(l.get(i), i)
}
l.maxLength = 3
assert.equal(l.length, 3)
for (var i = 0; i < 97; i ++) {
assert.equal(l.get(i), undefined)
}
for (var i = 98; i < 100; i ++) {
assert.equal(l.get(i), i)
}
// now remove the maxLength restriction, and try again.
l.maxLength = "hello"
for (var i = 0; i < 100; i ++) l.set(i, i)
assert.equal(l.length, 100)
for (var i = 0; i < 100; i ++) {
assert.equal(l.get(i), i)
}
// should trigger an immediate resize
l.maxLength = 3
assert.equal(l.length, 3)
for (var i = 0; i < 97; i ++) {
assert.equal(l.get(i), undefined)
}
for (var i = 98; i < 100; i ++) {
assert.equal(l.get(i), i)
}
})()

@@ -1,13 +0,13 @@

{ "name" : "lru-cache"
, "description" : "A cache object that deletes the least-recently-used items."
, "version" : "1.0.4"
, "author" : "Isaac Z. Schlueter <i@izs.me>"
, "scripts" : { "test" : "node lib/lru-cache.js" }
, "main" : "lib/lru-cache"
, "repository" : "git://github.com/isaacs/node-lru-cache.git"
, "licenses" :
[ { "type" : "MIT"
, "url" : "http://github.com/isaacs/node-lru-cache/raw/master/LICENSE"
}
]
{ "name": "lru-cache"
, "description": "A cache object that deletes the least-recently-used items."
, "version": "1.0.5"
, "author": "Isaac Z. Schlueter <i@izs.me>"
, "scripts": { "test": "tap test" }
, "main": "lib/lru-cache.js"
, "repository": "git://github.com/isaacs/node-lru-cache.git"
, "devDependencies": { "tap": "0.1" }
, "license":
{ "type": "MIT"
, "url": "http://github.com/isaacs/node-lru-cache/raw/master/LICENSE"
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc