Skip to content

Commit

Permalink
Clear all cache (#55)
Browse files Browse the repository at this point in the history
* Update lruStore.js - added function to clear all cache

* Added function to clear cache

* added test case for clearing cache
---------

Co-authored-by: Sethuraman Srinivasan <[email protected]>
  • Loading branch information
ramseth001 and Sethuraman Srinivasan authored Jan 27, 2024
1 parent 49db691 commit 6db8730
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,8 @@ module.exports.removeCache = function (url) {
cacheStore.del(url)
}

module.exports.clearCache = function () {
cacheStore.clear()
}

module.exports.cacheStore = cacheStore
4 changes: 4 additions & 0 deletions lruStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class LruStore {
async del (key) {
return Promise.resolve(this.lru.del(key))
}

async clear () {
return Promise.resolve(this.lru.reset())
}
}

module.exports = LruStore
17 changes: 15 additions & 2 deletions test/lruStore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* globals decribe */
/* globals describe */
'use strict'
const assert = require('assert')
const LruStore = require('../lruStore')
const LRU = require('lru-cache')

describe('# LRU Store test', function() {
const store = new LruStore({max: 1})
Expand All @@ -29,4 +28,18 @@ describe('# LRU Store test', function() {
await store.del('foo')
assert.equal(await store.get('foo'), undefined)
})

it('clears cache', async function() {
const store = new LruStore({max: 2})
await store.set('foo', 42)
await store.set('bar', 43)

assert.equal(await store.get('foo'), 42)
assert.equal(await store.get('bar'), 43)

await store.clear()

assert.equal(await store.get('foo'), undefined)
assert.equal(await store.get('bar'), undefined)
})
})

0 comments on commit 6db8730

Please sign in to comment.