Socket
Socket
Sign inDemoInstall

simple-lru-cache

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-lru-cache - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

servers

52

lib/simple_lru.js

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

"use strict";
/**

@@ -12,2 +14,11 @@ * LRU cache based on a double linked list

ListElement.prototype.setKey = function(key){
this.key = key
}
ListElement.prototype.setValue = function(value){
this.value = value
}
function Cache(options){

@@ -31,2 +42,6 @@ if(!options)

var cacheVal = this.cache[key]
/*
* Define if the egt function should hit the value to move
* it to the head of linked list
*/
hit = hit != undefined && hit != null ? hit : true;

@@ -42,3 +57,9 @@ if(cacheVal && hit)

var actual = this.cache[key]
hit = hit != undefined && hit != null ? hit : true;
/*
* Define if the set function should hit the value to move
* it to the head of linked list
*/
hit = hit != undefined && hit != null ? hit : true;
if(actual){

@@ -48,11 +69,28 @@ actual.value = val

}else{
var cacheVal = new ListElement(undefined,undefined,key,val)
var cacheVal
if(this.size >= this.maxSize){
var tailKey = this.tail.key
this.detach(this.tail)
/*
* If max is reached we'llreuse object to minimize GC impact
* when the objects are cached short time
*/
cacheVal = this.cache[tailKey]
delete this.cache[tailKey]
cacheVal.next = undefined
cacheVal.before = undefined
/*
* setters reuse the array object
*/
cacheVal.setKey(key)
cacheVal.setValue(val)
}
cacheVal = cacheVal ? cacheVal : new ListElement(undefined,undefined,key,val)
this.cache[key] = cacheVal
this.attach(cacheVal)
}
if(this.size>this.maxSize){
var tailKey = this.tail.key
this.detach(this.tail)
delete this.cache[tailKey]
}
}

@@ -59,0 +97,0 @@

6

package.json
{
"name": "simple-lru-cache",
"version": "0.0.1",
"version": "0.0.2",
"author": "Gabriel Eisbruch",

@@ -18,7 +18,7 @@ "description": "",

"type": "MIT",
"url": "https://github.com/mercadolibre/node-simple-lru-cache/blob/master/LICENSE"
"url": "https://github.com/geisbruch/node-simple-lru-cache/blob/master/LICENSE"
}],
"repositories": [{
"type": "git",
"url" : "http://github.com/mercadolibre/node-simple-lru-cache.git"
"url" : "http://github.com/geisbruch/node-simple-lru-cache.git"
}],

@@ -25,0 +25,0 @@ "dependencies": {

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