ttl-mem-cache
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -66,4 +66,7 @@ 'use strict'; | ||
del(key) { | ||
const item = this.store.get(key); | ||
const success = this.store.delete(key); | ||
this.emit('dispose', key); | ||
if (item) { | ||
this.emit('dispose', key, item.value); | ||
} | ||
return success; | ||
@@ -70,0 +73,0 @@ } |
{ | ||
"name": "ttl-mem-cache", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A in memory time to live cache with streaming support.", | ||
@@ -5,0 +5,0 @@ "main": "lib/cache.js", |
@@ -236,8 +236,8 @@ # ttl-mem-cache | ||
When an item is disposed (deleted) from the cache. Emits the `key` of the item. | ||
When an item is disposed (deleted) from the cache. Emits the `key` of the item and the item itself. | ||
```js | ||
const cache = new Cache(); | ||
cache.on('dispose', (key) => { | ||
console.log(key); // outputs: 'a' | ||
cache.on('dispose', (key, item) => { | ||
console.log(key, item); // outputs: "a, {foo: 'bar'}" | ||
}); | ||
@@ -244,0 +244,0 @@ cache.set('a', {foo: 'bar'}); |
@@ -277,6 +277,21 @@ 'use strict'; | ||
tap.test('cache.del() - remove set value - should return true', (t) => { | ||
const cache = new Cache(); | ||
cache.set('foo', 'bar'); | ||
t.equal(cache.del('foo'), true); | ||
t.end(); | ||
}); | ||
tap.test('cache.del() - remove unset value - should return false', (t) => { | ||
const cache = new Cache(); | ||
cache.set('foo', 'bar'); | ||
t.equal(cache.del('bar'), false); | ||
t.end(); | ||
}); | ||
tap.test('cache.del() - remove set value - should emit dispose event on removal', (t) => { | ||
const cache = new Cache(); | ||
cache.on('dispose', (key) => { | ||
cache.on('dispose', (key, item) => { | ||
t.equal(key, 'foo'); | ||
t.equal(item, 'bar'); | ||
t.end(); | ||
@@ -283,0 +298,0 @@ }); |
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
51442
886