exp-rediscache
Advanced tools
Comparing version 5.0.0 to 5.0.1
50
index.js
@@ -42,3 +42,25 @@ "use strict"; | ||
/* eslint-disable no-console */ | ||
if (typeof options.retry_strategy !== "undefined") { | ||
console.warn("retry_strategy is deprecated, please use retryStrategy instead."); | ||
options.retryStrategy = options.retry_strategy; | ||
} | ||
options.retryStrategy = options.retryStrategy || (() => DEFAULT_RETRY_MS); | ||
if (typeof options.prefix !== "undefined") { | ||
console.warn("prefix is deprecated, please use keyPrefix instead."); | ||
options.keyPrefix = options.prefix; | ||
} | ||
if (typeof options.no_ready_check !== "undefined") { | ||
console.warn("no_ready_check is deprecated, please use enableReadyCheck instead."); | ||
options.enableReadyCheck = !options.no_ready_check; | ||
} | ||
if (typeof options.enable_offline_queue !== "undefined") { | ||
console.warn("enable_offline_queue is deprecated, please use enableOfflineQueue instead."); | ||
options.enableOfflineQueue = options.enable_offline_queue; | ||
} | ||
/* eslint-enable */ | ||
this.options = options; | ||
@@ -68,3 +90,3 @@ const isNumberRegEx = /^\d+$/; | ||
async addGetToPool(key) { | ||
addGetToPool(key) { | ||
return new Promise((resolve, reject) => { | ||
@@ -115,3 +137,3 @@ const getVO = { | ||
async peek(key) { | ||
peek(key) { | ||
return this.get(key); | ||
@@ -125,3 +147,3 @@ } | ||
async set(key, value, maxAge) { | ||
set(key, value, maxAge) { | ||
const hasTtl = typeof maxAge === "number"; | ||
@@ -131,17 +153,17 @@ const hasDefaultMaxAge = this.options.maxAge; | ||
if (hasTtl && maxAge <= 0) { | ||
return Promise.resolve(); | ||
} else if (hasTtl && maxAge > 0) { | ||
return this.client.setex( | ||
key, | ||
Math.round(maxAge / 1000), | ||
serialize(value) | ||
); | ||
return; | ||
} | ||
const serialized = serialize(value); | ||
const args = [key, serialized]; | ||
if (hasTtl && maxAge > 0) { | ||
args.push("PX", maxAge); | ||
} else if (hasDefaultMaxAge) { | ||
return this.set(key, value, Number(this.options.maxAge)); | ||
} else { | ||
return this.client.set(key, serialize(value)); | ||
args.push("PX", Number(this.options.maxAge)); | ||
} | ||
return this.client.set(...args); | ||
} | ||
async del(key) { | ||
del(key) { | ||
return this.client.del(key); | ||
@@ -148,0 +170,0 @@ } |
{ | ||
"name": "exp-rediscache", | ||
"description": "A simple redis cache library", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"author": "AB Kvällstidningen Expressen", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -9,9 +9,9 @@ rediscache | ||
```javascript | ||
var cache = new AsyncCache(new RedisCache()); | ||
const cache = new AsyncCache(new RedisCache()); | ||
var hit = cache.lookup("foo", function (resolve) { | ||
const hit = cache.lookup("foo", (resolve) => { | ||
resolve(null, "baz"); | ||
}); | ||
hit.then(function (value) { | ||
hit.then((value) => { | ||
console.log(value); // value will be "baz" | ||
@@ -24,9 +24,9 @@ }); | ||
```javascript | ||
var cache = new AsyncCache(new RedisCache()); | ||
const cache = new AsyncCache(new RedisCache()); | ||
var hit = cache.lookup("foo", function (resolve) { | ||
const hit = cache.lookup("foo", (resolve) => { | ||
resolve(null, "baz", 1000); | ||
}); | ||
hit.then(function (value) { | ||
hit.then((value) => { | ||
console.log(value); // value will be "baz" | ||
@@ -36,15 +36,15 @@ }); | ||
The underlying Redis client will queue up any commands if Redis is down. If you want instant errors back you can set the `enable_offline_queue` option to `false`. This allows [exp-asynccache](https://github.com/ExpressenAB/exp-asynccache) to transparently fall back to the resolve callback in such a case. | ||
The underlying Redis client will queue up any commands if Redis is down. If you want instant errors back you can set the `enableOfflineQueue` option to `false`. This allows [exp-asynccache](https://github.com/ExpressenAB/exp-asynccache) to transparently fall back to the resolve callback in such a case. | ||
```javascript | ||
var cache = new AsyncCache(new RedisCache({ | ||
enable_offline_queue: false | ||
const cache = new AsyncCache(new RedisCache({ | ||
enableOfflineQueue: false | ||
})); | ||
``` | ||
To namespace your cache keys (in case you run multiple apps against the same Redis), you can specify the `prefix` option. | ||
To namespace your cache keys (in case you run multiple apps against the same Redis), you can specify the `keyPrefix` option. | ||
```javascript | ||
var cache = new AsyncCache(new RedisCache({ | ||
prefix: "namespace" | ||
const cache = new AsyncCache(new RedisCache({ | ||
keyPrefix: "namespace" | ||
})); | ||
@@ -51,0 +51,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7539
145
0