Comparing version 3.0.0 to 3.1.0
@@ -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 |
{ | ||
"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) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14584
349
102