Skip to content

Commit

Permalink
feat: changes to lru-cache since dependency update
Browse files Browse the repository at this point in the history
no more maxAge
del -> delete
reset -> clear
  • Loading branch information
meenahoda authored and Meena Brend committed Nov 2, 2022
1 parent 2ce4df1 commit e2c3a7d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
17 changes: 6 additions & 11 deletions lib/plugin/components/services/caches/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,10 @@ class CacheService {
* @param cacheName the cache identifier
* @param key key with the specified value is to be associated
* @param value the value to be associated with the specified key
* @param maxAge optional parameter, which overrides the cache configuration if provided
* @returns {undefined}
*/
set (cacheName, key, value, maxAge) {
if (maxAge) {
this[cacheName].set(key, value, maxAge)
} else {
this[cacheName].set(key, value)
}
set (cacheName, key, value) {
this[cacheName].set(key, value)
}

/**
Expand Down Expand Up @@ -93,16 +88,16 @@ class CacheService {
* @param key the key whose mapping is to be removed from the specified cache
* @returns {undefined}
*/
del (cacheName, key) {
this[cacheName].del(key)
delete (cacheName, key) {
this[cacheName].delete(key)
}

/**
* Clears the specified cache entirely, throwing away all values
* @param cacheName the cache identifier
*/
reset (cacheName) {
this[cacheName].reset()
clear (cacheName) {
this[cacheName].clear()
}
}

Expand Down
4 changes: 0 additions & 4 deletions lib/plugin/components/services/caches/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
"max": {
"type": "number",
"description": "The maximum size of the cache, checked by applying the length function to all values in the cache. Not setting this will fall-back to a service-level default."
},
"maxAge": {
"type": "number",
"description": "Maximum age in ms. Items are not pro-actively pruned out as they age, but if you try to get an item that is too old, it'll drop it and return undefined"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/components/services/registry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class RegistryService {
return callbackify(this.clear(key), callback)
}
await this.registryKeyModel.destroyById(key)
this.caches.del(cacheName, key)
this.caches.delete(cacheName, key)
await this.refresh()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = class DeleteCacheItem {
const { cacheName, key } = event

try {
this.caches.del(cacheName, key)
this.caches.delete(cacheName, key)
return context.sendTaskSuccess()
} catch (err) {
return context.sendTaskFailure({ error: 'DeleteCacheItemFail', cause: err })
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/components/state-resources/reset-cache/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = class ResetCache {

run (event, context) {
try {
this.caches.reset(event)
this.caches.clear(event)
return context.sendTaskSuccess()
} catch (err) {
return context.sendTaskFailure({ error: 'ResetCacheFail', cause: err })
Expand Down
4 changes: 2 additions & 2 deletions test/cache-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Cache tests', function () {
})

it('delete the cache', () => {
cacheService.del('users', 'user1')
cacheService.delete('users', 'user1')
})

it('check the key has been removed from the cahce', () => {
Expand All @@ -53,7 +53,7 @@ describe('Cache tests', function () {
})

it('reset the cache', () => {
cacheService.reset('users')
cacheService.clear('users')
})

it('check the cache is empty', () => {
Expand Down

0 comments on commit e2c3a7d

Please sign in to comment.