core.io-cache-redis
Advanced tools
Comparing version 0.3.0 to 0.3.2
@@ -63,11 +63,18 @@ 'use strict'; | ||
* @param {Boolean} [addTimestamp=true] Include a timestamp to payload | ||
* @param {Boolean} [throwOnError=false] Throw if fallback errors | ||
* @returns {Promise} | ||
*/ | ||
async tryGet(key, fallback, ttl = this.defaultTtl, serialize = true, addTimestamp = true) { | ||
async tryGet(key, fallback, ttl = this.defaultTtl, serialize = true, addTimestamp = true, throwOnError = false) { | ||
key = this.hashKey(key); | ||
this.logger.info('try to fetch key "%s" from cache...', key); | ||
let value = await this.get(key, false, serialize); | ||
if (value) return value; | ||
if (value) { | ||
this.logger.info('value was cached, return'); | ||
return value; | ||
} | ||
try { | ||
@@ -87,2 +94,3 @@ value = await fallback(); | ||
this.handleError(error, 'cache try error'); | ||
if (throwOnError) throw error; | ||
} | ||
@@ -89,0 +97,0 @@ |
@@ -8,2 +8,3 @@ 'use strict'; | ||
const Redis = require('ioredis'); | ||
return new Redis(url); | ||
@@ -10,0 +11,0 @@ } |
{ | ||
"name": "core.io-cache-redis", | ||
"version": "0.3.0", | ||
"version": "0.3.2", | ||
"description": "Redis cache module", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
11114
222