@sebspark/promise-cache 3.3.1 → 3.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +9 -8
- package/dist/index.mjs +6 -5
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -18,12 +18,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
Persistor: () => Persistor,
|
|
24
24
|
PromiseCache: () => PromiseCache
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// src/promiseCache.ts
|
|
29
29
|
var import_node_crypto = require("crypto");
|
|
@@ -113,13 +113,14 @@ var Persistor = class {
|
|
|
113
113
|
var _a;
|
|
114
114
|
try {
|
|
115
115
|
await new Promise((resolve, reject) => {
|
|
116
|
-
var _a2, _b, _c, _d;
|
|
116
|
+
var _a2, _b, _c, _d, _e;
|
|
117
117
|
this.client = CACHE_CLIENT({
|
|
118
118
|
url: (_a2 = this.redis) == null ? void 0 : _a2.url,
|
|
119
119
|
username: (_b = this.redis) == null ? void 0 : _b.username,
|
|
120
120
|
password: (_c = this.redis) == null ? void 0 : _c.password,
|
|
121
|
+
pingInterval: ((_d = this.redis) == null ? void 0 : _d.pingInterval) || void 0,
|
|
121
122
|
socket: {
|
|
122
|
-
...(
|
|
123
|
+
...(_e = this.redis) == null ? void 0 : _e.socket,
|
|
123
124
|
reconnectStrategy: (retries, cause) => {
|
|
124
125
|
console.error(cause);
|
|
125
126
|
return 1e3 * 2 ** retries;
|
|
@@ -290,7 +291,7 @@ var PromiseCache = class {
|
|
|
290
291
|
});
|
|
291
292
|
this.caseSensitive = caseSensitive;
|
|
292
293
|
if (ttlInSeconds) {
|
|
293
|
-
this.ttl = ttlInSeconds
|
|
294
|
+
this.ttl = ttlInSeconds;
|
|
294
295
|
}
|
|
295
296
|
}
|
|
296
297
|
/**
|
|
@@ -334,7 +335,7 @@ var PromiseCache = class {
|
|
|
334
335
|
async wrap(key, delegate, ttlInSeconds, ttlKeyInSeconds) {
|
|
335
336
|
const now = Date.now();
|
|
336
337
|
const effectiveKey = this.caseSensitive ? key : key.toLowerCase();
|
|
337
|
-
let effectiveTTL = ttlInSeconds
|
|
338
|
+
let effectiveTTL = ttlInSeconds ?? this.ttl;
|
|
338
339
|
const cached = await this.persistor.get(effectiveKey);
|
|
339
340
|
if (cached) {
|
|
340
341
|
if (!ttlKeyInSeconds && cached.ttl !== effectiveTTL) {
|
|
@@ -347,7 +348,7 @@ var PromiseCache = class {
|
|
|
347
348
|
const response = await delegate();
|
|
348
349
|
if (ttlKeyInSeconds) {
|
|
349
350
|
const responseDict = response;
|
|
350
|
-
const responseTTL = Number(responseDict[ttlKeyInSeconds])
|
|
351
|
+
const responseTTL = Number(responseDict[ttlKeyInSeconds]);
|
|
351
352
|
effectiveTTL = responseTTL || effectiveTTL;
|
|
352
353
|
}
|
|
353
354
|
this.persistor.set(effectiveKey, {
|
package/dist/index.mjs
CHANGED
|
@@ -93,13 +93,14 @@ var Persistor = class {
|
|
|
93
93
|
var _a;
|
|
94
94
|
try {
|
|
95
95
|
await new Promise((resolve, reject) => {
|
|
96
|
-
var _a2, _b, _c, _d;
|
|
96
|
+
var _a2, _b, _c, _d, _e;
|
|
97
97
|
this.client = CACHE_CLIENT({
|
|
98
98
|
url: (_a2 = this.redis) == null ? void 0 : _a2.url,
|
|
99
99
|
username: (_b = this.redis) == null ? void 0 : _b.username,
|
|
100
100
|
password: (_c = this.redis) == null ? void 0 : _c.password,
|
|
101
|
+
pingInterval: ((_d = this.redis) == null ? void 0 : _d.pingInterval) || void 0,
|
|
101
102
|
socket: {
|
|
102
|
-
...(
|
|
103
|
+
...(_e = this.redis) == null ? void 0 : _e.socket,
|
|
103
104
|
reconnectStrategy: (retries, cause) => {
|
|
104
105
|
console.error(cause);
|
|
105
106
|
return 1e3 * 2 ** retries;
|
|
@@ -270,7 +271,7 @@ var PromiseCache = class {
|
|
|
270
271
|
});
|
|
271
272
|
this.caseSensitive = caseSensitive;
|
|
272
273
|
if (ttlInSeconds) {
|
|
273
|
-
this.ttl = ttlInSeconds
|
|
274
|
+
this.ttl = ttlInSeconds;
|
|
274
275
|
}
|
|
275
276
|
}
|
|
276
277
|
/**
|
|
@@ -314,7 +315,7 @@ var PromiseCache = class {
|
|
|
314
315
|
async wrap(key, delegate, ttlInSeconds, ttlKeyInSeconds) {
|
|
315
316
|
const now = Date.now();
|
|
316
317
|
const effectiveKey = this.caseSensitive ? key : key.toLowerCase();
|
|
317
|
-
let effectiveTTL = ttlInSeconds
|
|
318
|
+
let effectiveTTL = ttlInSeconds ?? this.ttl;
|
|
318
319
|
const cached = await this.persistor.get(effectiveKey);
|
|
319
320
|
if (cached) {
|
|
320
321
|
if (!ttlKeyInSeconds && cached.ttl !== effectiveTTL) {
|
|
@@ -327,7 +328,7 @@ var PromiseCache = class {
|
|
|
327
328
|
const response = await delegate();
|
|
328
329
|
if (ttlKeyInSeconds) {
|
|
329
330
|
const responseDict = response;
|
|
330
|
-
const responseTTL = Number(responseDict[ttlKeyInSeconds])
|
|
331
|
+
const responseTTL = Number(responseDict[ttlKeyInSeconds]);
|
|
331
332
|
effectiveTTL = responseTTL || effectiveTTL;
|
|
332
333
|
}
|
|
333
334
|
this.persistor.set(effectiveKey, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/promise-cache",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"tsconfig": "*"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"fix-esm": "
|
|
22
|
+
"fix-esm": "1.0.1",
|
|
23
23
|
"redis": "4.7.0",
|
|
24
|
-
"superjson": "
|
|
24
|
+
"superjson": "2.2.2"
|
|
25
25
|
}
|
|
26
26
|
}
|