Socket
Socket
Sign inDemoInstall

lru

Package Overview
Dependencies
1
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.1.0

3

example/usage.js

@@ -24,1 +24,4 @@ var LRU = require('../')

console.log(evicted) // => evicted = { key: 'foo', value: 'bar' }
cache.clear() // it will NOT emit the 'evict' event
console.log(cache.length) // => 0

@@ -24,2 +24,8 @@ var events = require('events')

LRU.prototype.clear = function () {
this.cache = {}
this.head = this.tail = null
this.length = 0
}
LRU.prototype.remove = function (key) {

@@ -26,0 +32,0 @@ if (typeof key !== 'string') key = '' + key

2

package.json
{
"name": "lru",
"description": "A simple O(1) LRU cache",
"version": "3.0.0",
"version": "3.1.0",
"author": "Chris O'Hara <cohara87@gmail.com>",

@@ -6,0 +6,0 @@ "main": "index",

@@ -32,2 +32,7 @@ # lru

cache.length // => 1
cache.keys // => ['foo3']
cache.clear() // => it will NOT emit the 'evict' event
cache.length // => 0
cache.keys // => []
```

@@ -80,4 +85,8 @@

**Returns**: value of key if found; `undefined` otherwise.
##### `.clear()`
Clear the cache. This method does **NOT** emit the `evict` event.
##### `.on( event, callback )`

@@ -84,0 +93,0 @@ Respond to events. Currently only the `evict` event is implemented. When a key is evicted, the callback is executed with an associative array containing the evicted key: `{key: key, value: value}`.

@@ -8,2 +8,16 @@ var assert = require('assert')

suite.addBatch({
'clear() sets the cache to its initial state': function () {
var lru = new LRU(2)
var json1 = JSON.stringify(lru)
lru.set('foo', 'bar')
lru.clear()
var json2 = JSON.stringify(lru)
assert.equal(json2, json1)
}
})
suite.addBatch({
'setting keys doesn\'t grow past max size': function () {

@@ -10,0 +24,0 @@ var lru = new LRU(3)

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