@scayle/storefront-core 7.24.0 → 7.24.1
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/CHANGELOG.md +6 -0
- package/dist/cache/cached.cjs +14 -19
- package/dist/cache/cached.mjs +14 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cache/cached.cjs
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Cached = void 0;
|
|
7
|
-
var _radash = require("radash");
|
|
8
7
|
var _autobind = require("../helpers/autobind.cjs");
|
|
9
8
|
var _utils = require("../utils/index.cjs");
|
|
10
9
|
var _hash = require("../utils/hash.cjs");
|
|
@@ -34,23 +33,22 @@ class Cached {
|
|
|
34
33
|
const prefix = options?.cacheKeyPrefix ?? fn.name;
|
|
35
34
|
const params = [...args, this?.prefix];
|
|
36
35
|
const cacheKey = options?.cacheKey ?? (await this.createCacheKey(params, prefix));
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
try {
|
|
37
|
+
const cachedResponse = await this.getCacheValue(cacheKey, options);
|
|
38
|
+
if (cachedResponse !== void 0 && cachedResponse !== null) {
|
|
39
|
+
return cachedResponse;
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {
|
|
42
|
+
this.handleError(e);
|
|
40
43
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
const [error, response] = await (0, _radash.tryit)(fn)(...args);
|
|
45
|
-
if (error) {
|
|
46
|
-
this.handleError(error);
|
|
47
|
-
}
|
|
48
|
-
if (cacheGetError) {
|
|
44
|
+
const response = await fn(...args);
|
|
45
|
+
if (response === void 0 || response === null) {
|
|
49
46
|
return response;
|
|
50
47
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
try {
|
|
49
|
+
await this.setCacheValue(cacheKey, response, options);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
this.handleError(e);
|
|
54
52
|
}
|
|
55
53
|
return response;
|
|
56
54
|
};
|
|
@@ -76,14 +74,11 @@ class Cached {
|
|
|
76
74
|
async createCacheKey(params, prefix = "") {
|
|
77
75
|
return [prefix, await (0, _hash.sha256)(JSON.stringify(params))].join(":");
|
|
78
76
|
}
|
|
79
|
-
handleError(error
|
|
77
|
+
handleError(error) {
|
|
80
78
|
if (error.message === "timeout") {
|
|
81
79
|
return this.log.error("Cache timeout");
|
|
82
80
|
}
|
|
83
81
|
this.log.error(error);
|
|
84
|
-
if (shouldThrow) {
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
82
|
}
|
|
88
83
|
}
|
|
89
84
|
exports.Cached = Cached;
|
package/dist/cache/cached.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { tryit } from "radash";
|
|
2
1
|
import { autobind } from "../helpers/autobind.mjs";
|
|
3
2
|
import { timeout } from "../utils/index.mjs";
|
|
4
3
|
import { sha256 } from "../utils/hash.mjs";
|
|
@@ -28,30 +27,22 @@ export class Cached {
|
|
|
28
27
|
const prefix = options?.cacheKeyPrefix ?? fn.name;
|
|
29
28
|
const params = [...args, this?.prefix];
|
|
30
29
|
const cacheKey = options?.cacheKey ?? await this.createCacheKey(params, prefix);
|
|
31
|
-
|
|
32
|
-
cacheKey,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
try {
|
|
31
|
+
const cachedResponse = await this.getCacheValue(cacheKey, options);
|
|
32
|
+
if (cachedResponse !== void 0 && cachedResponse !== null) {
|
|
33
|
+
return cachedResponse;
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
this.handleError(e);
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
const [error, response] = await tryit(fn)(...args);
|
|
42
|
-
if (error) {
|
|
43
|
-
this.handleError(error);
|
|
44
|
-
}
|
|
45
|
-
if (cacheGetError) {
|
|
38
|
+
const response = await fn(...args);
|
|
39
|
+
if (response === void 0 || response === null) {
|
|
46
40
|
return response;
|
|
47
41
|
}
|
|
48
|
-
|
|
49
|
-
cacheKey,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
if (cacheSetError) {
|
|
54
|
-
this.handleError(cacheSetError);
|
|
42
|
+
try {
|
|
43
|
+
await this.setCacheValue(cacheKey, response, options);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
this.handleError(e);
|
|
55
46
|
}
|
|
56
47
|
return response;
|
|
57
48
|
};
|
|
@@ -80,13 +71,10 @@ export class Cached {
|
|
|
80
71
|
async createCacheKey(params, prefix = "") {
|
|
81
72
|
return [prefix, await sha256(JSON.stringify(params))].join(":");
|
|
82
73
|
}
|
|
83
|
-
handleError(error
|
|
74
|
+
handleError(error) {
|
|
84
75
|
if (error.message === "timeout") {
|
|
85
76
|
return this.log.error("Cache timeout");
|
|
86
77
|
}
|
|
87
78
|
this.log.error(error);
|
|
88
|
-
if (shouldThrow) {
|
|
89
|
-
throw error;
|
|
90
|
-
}
|
|
91
79
|
}
|
|
92
80
|
}
|