core.io-cache-redis
Advanced tools
Comparing version 0.14.0 to 0.15.0
@@ -72,3 +72,3 @@ 'use strict'; | ||
key = this.hashKey(rawKey); | ||
key = this.hashKey(rawKey, options); | ||
@@ -79,3 +79,3 @@ let value; | ||
try { | ||
this.logger.info('fetching "%s"', key); | ||
this.logger.info('fetch "%s"', key); | ||
value = await this.get(key, false, options); | ||
@@ -90,3 +90,3 @@ } catch (error) { | ||
if (value) { | ||
this.logger.info('returning cached value!'); | ||
this.logger.info('cache OK "%s"', key); | ||
return value; | ||
@@ -172,6 +172,6 @@ } | ||
if (deserialize === true) { | ||
return this.deserialize(value); | ||
return await this.deserialize(value, options); | ||
} | ||
if (typeof deserialize === 'function') return deserialize(value); | ||
if (typeof deserialize === 'function') return await deserialize(value, options); | ||
@@ -189,4 +189,4 @@ return value; | ||
*/ | ||
set(key, value, options = {}) { | ||
key = this.hashKey(key); | ||
async set(key, value, options = {}) { | ||
key = this.hashKey(key, options); | ||
@@ -204,3 +204,3 @@ let defaultTTL = this.defaultTTL; | ||
if (typeof value !== 'string') value = serialize(value); | ||
if (typeof value !== 'string') value = await serialize(value, options); | ||
@@ -217,3 +217,3 @@ return this.client.set(key, value, this.timeUnit, ttl); | ||
del(key) { | ||
key = this.hashKey(key); | ||
key = this.hashKey(key, options); | ||
return this.client.del(key); | ||
@@ -239,8 +239,8 @@ } | ||
*/ | ||
hashKey(key) { | ||
hashKey(key, options = {}) { | ||
if (this.hashKeys === false) return key; | ||
if (typeof key !== 'string') key = this.keySerializer(key); | ||
if (this.isHashKey(key)) return key; | ||
if (typeof key !== 'string') key = this.keySerializer(key, options); | ||
if (this.isHashKey(key, options)) return key; | ||
let hash = this.keyHashFunction(key); | ||
let hash = this.keyHashFunction(key, options); | ||
@@ -254,4 +254,4 @@ if (this.hasUUIDFormat(key) && this.hashUUIDs === false) { | ||
isHashKey(key) { | ||
if (typeof key !== 'string') key = this.keySerializer(key); | ||
isHashKey(key, options = {}) { | ||
if (typeof key !== 'string') key = this.keySerializer(key, options); | ||
return !!this.cacheKeyMatcher.exec(key); | ||
@@ -258,0 +258,0 @@ } |
@@ -48,3 +48,3 @@ const extend = require('gextend'); | ||
*/ | ||
keys = this.hashKeyBatch(keys); | ||
keys = this.hashKeyBatch(keys, options); | ||
@@ -188,3 +188,3 @@ | ||
keys = this.hashKeyBatch(keys); | ||
keys = this.hashKeyBatch(keys, o); | ||
@@ -203,11 +203,11 @@ /** | ||
const _deserializer = val => { | ||
const _deserializer = (val, o) => { | ||
if (!deserialize || val == null) return val; | ||
return typeof deserialize === 'function' ? | ||
deserialize(val) : | ||
this.deserialize(val); | ||
deserialize(val, o) : | ||
this.deserialize(val, o); | ||
}; | ||
for (const index in values) { | ||
let value = _deserializer(values[index]); | ||
let value = await _deserializer(values[index], o); | ||
if (value === null && (index in defs)) { | ||
@@ -222,4 +222,3 @@ value = defs[index]; | ||
setBatch(keys, values, o = {}) { | ||
async setBatch(keys, values, o = {}) { | ||
if (notValidArguments(keys, values)) { | ||
@@ -244,3 +243,3 @@ throw new CacheClientError( | ||
let value = values[index]; | ||
if (typeof value !== 'string') value = serialize(value); | ||
if (typeof value !== 'string') value = await serialize(value, o); | ||
if (value) tx.set(key, value, this.timeUnit, ttl); | ||
@@ -257,5 +256,5 @@ } | ||
*/ | ||
delBatch(keys) { | ||
delBatch(keys, options = {}) { | ||
if (!Array.isArray(keys)) keys = [keys]; | ||
keys = this.hashKeyBatch(keys); | ||
keys = this.hashKeyBatch(keys, options); | ||
return this.client.del(keys); | ||
@@ -262,0 +261,0 @@ } |
@@ -39,3 +39,3 @@ const extend = require('gextend'); | ||
*/ | ||
cacheKeyMatcher: /^cache:[a-z0-9]{32}$/i, | ||
cacheKeyMatcher: /^cache:(.*)$/i, | ||
/** | ||
@@ -71,6 +71,6 @@ * Should we hash raw keys | ||
*/ | ||
keySerializer(obj) { | ||
keySerializer(obj, options = {}) { | ||
return this.serialize(obj); | ||
}, | ||
keyHashFunction(key) { | ||
keyHashFunction(key, options = {}) { | ||
return crypto.createHash('md5').update(key).digest('hex'); | ||
@@ -77,0 +77,0 @@ }, |
{ | ||
"name": "core.io-cache-redis", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"description": "Redis cache module", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
31467