Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lru-cache

Package Overview
Dependencies
Maintainers
2
Versions
143
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 3.0.0 to 3.1.0

4

lib/lru-cache.js

@@ -58,3 +58,3 @@ module.exports = LRUCache

this._cache.forEach(function (value, key) {
value.length = this._lengthCalculator(value.value)
value.length = this._lengthCalculator(value.value, key)
this._length += value.length

@@ -162,3 +162,3 @@ })

var now = maxAge ? Date.now() : 0
var len = this._lengthCalculator(value)
var len = this._lengthCalculator(value, key)

@@ -165,0 +165,0 @@ if (this._cache.has(key)) {

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

@@ -6,0 +6,0 @@ "keywords": [

@@ -10,3 +10,3 @@ # lru cache

, options = { max: 500
, length: function (n) { return n * 2 }
, length: function (n, key) { return n * 2 + key.length }
, dispose: function (key, n) { n.close() }

@@ -45,5 +45,6 @@ , maxAge: 1000 * 60 * 60 }

items. If you're storing strings or buffers, then you probably want
to do something like `function(n){return n.length}`. The default is
`function(n){return 1}`, which is fine if you want to store `max`
like-sized things.
to do something like `function(n, key){return n.length}`. The default is
`function(){return 1}`, which is fine if you want to store `max`
like-sized things. They item is passed as the first argument, and
the key is passed as the second argumnet.
* `dispose` Function that is called on items when they are dropped

@@ -50,0 +51,0 @@ from the cache. This can be handy if you want to close file

@@ -99,3 +99,6 @@ var test = require("tap").test

max: 100,
length: function (item) { return item.size }
length: function (item, key) {
t.isa(key, 'string')
return item.size
}
})

@@ -105,3 +108,3 @@ cache.set("key", {val: "value", size: 50})

t.equal(cache.get("nada"), undefined)
t.equal(cache.lengthCalculator(cache.get("key")), 50)
t.equal(cache.lengthCalculator(cache.get("key"), 'key'), 50)
t.equal(cache.length, 50)

@@ -108,0 +111,0 @@ t.equal(cache.max, 100)

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