diff options
| author | 8cy <[email protected]> | 2020-04-03 02:37:42 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-03 02:37:42 -0700 |
| commit | 60867fb030bae582082340ead7dbc7efdc2f5398 (patch) | |
| tree | 4c6a7356351be2e4914e15c4703172597c45656e /node_modules/node-file-cache/tests/expire-test.js | |
| parent | commenting (diff) | |
| download | s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.tar.xz s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.zip | |
2020/04/03, 02:34, v1.2.0
Diffstat (limited to 'node_modules/node-file-cache/tests/expire-test.js')
| -rw-r--r-- | node_modules/node-file-cache/tests/expire-test.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/node_modules/node-file-cache/tests/expire-test.js b/node_modules/node-file-cache/tests/expire-test.js new file mode 100644 index 0000000..9f39529 --- /dev/null +++ b/node_modules/node-file-cache/tests/expire-test.js @@ -0,0 +1,70 @@ +'use strict'; + +const assert = require('assert'); +const cache = require('../lib/index').create(); + +cache.clear(); +assert.equal(cache.size(), 0); + +const items = [ + { + key: 'one', + item: { + name: 'one' + }, + options: {} + }, + { + key: 'two', + item: { + name: 'two' + }, + options: { + tags: [ 'two' ] + } + }, + { + key: 'three', + item: { + name: 'three' + }, + options: { + life: 60 + } + }, + { + key: 'four', + item: { + name: 'four' + }, + options: { + tags: [ 'four' ], + life: -1 + } + } +]; + +items.forEach((item) => { + cache.set(item.key, item.item, item.options); +}); + +assert.equal(cache.size(), items.length); + +// expire by key +cache.expire('one'); +assert.equal(cache.get('one'), null); +assert.equal(cache.size(), items.length - 1); + +// expire by tags +cache.expire(['two']); +assert.equal(cache.get('two'), null); +assert.equal(cache.size(), items.length - 2); + +// expire by callback +cache.expire((record) => record.key === 'three'); +assert.equal(cache.get('three'), null); +assert.equal(cache.size(), items.length - 3); + +// expire by lifespan +assert.equal(cache.get('four'), null); +assert.equal(cache.size(), items.length - 4);
\ No newline at end of file |