dobi-cache-2
Advanced tools
Comparing version 3.0.3 to 3.0.4
@@ -32,2 +32,13 @@ /* eslint-disable no-process-env */ | ||
async flushCache() { | ||
const keys = this.redis.keys('dobiCache:*'); | ||
for (const key of keys) { | ||
await this.delete(key); | ||
} | ||
} | ||
static getKey(key) { | ||
return `dobiCache:${key}`; | ||
} | ||
async delete(key) { | ||
@@ -37,3 +48,3 @@ if (this.disabled) { | ||
} | ||
return this.redis.del(key); | ||
return this.redis.del(Cache.getKey(key)); | ||
} | ||
@@ -46,3 +57,3 @@ | ||
try { | ||
const { type, value } = await this.redis.get(key); | ||
const { type, value } = await this.redis.get(Cache.getKey(key)); | ||
if (type === 'object') { | ||
@@ -76,3 +87,3 @@ return JSON.parse(value); | ||
} | ||
await this.redis.set(key, JSON.stringify({ type, value })); | ||
await this.redis.set(Cache.getKey(key), JSON.stringify({ type, value })); | ||
await this.redis.expire(key, ttl); | ||
@@ -79,0 +90,0 @@ } |
@@ -8,3 +8,5 @@ 'use strict'; | ||
module.exports = ({ config, fn, options }) => asyncWrapper(async (req, res) => { | ||
let flushCache = async () => {}; | ||
const middleware = ({ config, fn, options }) => asyncWrapper(async (req, res) => { | ||
const fetch = (callback) => { | ||
@@ -43,2 +45,5 @@ const cb = value => callback(null, value); | ||
await cache.connect(); | ||
if (!cache.disabled) { | ||
({ flushCache } = cache); | ||
} | ||
@@ -111,1 +116,6 @@ | ||
}); | ||
module.exports = { | ||
flushCache, | ||
middleware, | ||
}; |
@@ -27,3 +27,3 @@ { | ||
}, | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"devDependencies": { | ||
@@ -30,0 +30,0 @@ "eslint": "^5.5.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
21986
342