spice-js 2.6.55 → 2.6.57
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.
|
@@ -8,6 +8,13 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
8
8
|
|
|
9
9
|
var NodeCache = require("node-cache");
|
|
10
10
|
|
|
11
|
+
var crypto = require("crypto");
|
|
12
|
+
|
|
13
|
+
function generateCacheKey(input) {
|
|
14
|
+
// Create an MD5 hash of the input string and return it in hexadecimal format
|
|
15
|
+
return crypto.createHash("md5").update(input).digest("hex");
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
module.exports = class SpiceCache {
|
|
12
19
|
constructor(args) {
|
|
13
20
|
if (args === void 0) {
|
|
@@ -45,9 +52,9 @@ module.exports = class SpiceCache {
|
|
|
45
52
|
ttl,
|
|
46
53
|
namespace = ""
|
|
47
54
|
} = working_options;
|
|
48
|
-
|
|
55
|
+
var workingKey = namespace + key;
|
|
49
56
|
|
|
50
|
-
_this2.client.set(
|
|
57
|
+
_this2.client.set(generateCacheKey(workingKey), value, ttl == undefined ? 60 : ttl);
|
|
51
58
|
})();
|
|
52
59
|
}
|
|
53
60
|
|
|
@@ -60,7 +67,12 @@ module.exports = class SpiceCache {
|
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
try {
|
|
63
|
-
|
|
70
|
+
var {
|
|
71
|
+
namespace = ""
|
|
72
|
+
} = options;
|
|
73
|
+
var workingKey = namespace + key;
|
|
74
|
+
var cacheKey = generateCacheKey(workingKey);
|
|
75
|
+
return _this3.client.get(cacheKey);
|
|
64
76
|
} catch (e) {
|
|
65
77
|
return null;
|
|
66
78
|
}
|
|
@@ -71,7 +83,8 @@ module.exports = class SpiceCache {
|
|
|
71
83
|
var _this4 = this;
|
|
72
84
|
|
|
73
85
|
return _asyncToGenerator(function* () {
|
|
74
|
-
|
|
86
|
+
var cacheKey = generateCacheKey(key);
|
|
87
|
+
return yield _this4.client.has(cacheKey);
|
|
75
88
|
})();
|
|
76
89
|
}
|
|
77
90
|
|
|
@@ -929,10 +929,6 @@ class SpiceModel {
|
|
|
929
929
|
}
|
|
930
930
|
|
|
931
931
|
filterResultsByColumns(data, columns) {
|
|
932
|
-
if (this.type === "user") {
|
|
933
|
-
console.log("Filter Columns::", columns);
|
|
934
|
-
}
|
|
935
|
-
|
|
936
932
|
if (columns && columns !== "") {
|
|
937
933
|
// Remove backticks and replace meta().id with id
|
|
938
934
|
var cleanedColumns = columns.replace(/`/g, "").replace(/meta\(\)\.id/g, "id"); // Process each column by splitting on comma and trimming
|
|
@@ -1126,12 +1122,17 @@ class SpiceModel {
|
|
|
1126
1122
|
if (_this12.shouldUseCache(_this12.type)) {
|
|
1127
1123
|
var cachedResults = yield _this12.getCacheProviderObject(_this12.type).get(cacheKey);
|
|
1128
1124
|
results = cachedResults == null ? void 0 : cachedResults.value;
|
|
1129
|
-
|
|
1125
|
+
|
|
1126
|
+
if ((cachedResults == null ? void 0 : cachedResults.value) === undefined) {
|
|
1130
1127
|
results = yield _this12.fetchResults(args, query);
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1128
|
+
} else {
|
|
1129
|
+
if (!results || (yield _this12.shouldForceRefresh(cachedResults))) {
|
|
1130
|
+
results = yield _this12.fetchResults(args, query);
|
|
1131
|
+
yield _this12.getCacheProviderObject(_this12.type).set(cacheKey, {
|
|
1132
|
+
value: results,
|
|
1133
|
+
time: new Date().getTime()
|
|
1134
|
+
}, _this12.getCacheConfig(_this12.type));
|
|
1135
|
+
}
|
|
1135
1136
|
}
|
|
1136
1137
|
} else {
|
|
1137
1138
|
results = yield _this12.fetchResults(args, query);
|
|
@@ -1141,8 +1142,6 @@ class SpiceModel {
|
|
|
1141
1142
|
results.data = yield _this12.do_serialize(results.data, "read", {}, args, (yield _this12.propsToBeRemoved(results.data)));
|
|
1142
1143
|
}
|
|
1143
1144
|
|
|
1144
|
-
if (_this12.type == "user") console.log("results", results.data);
|
|
1145
|
-
|
|
1146
1145
|
if (args.skip_hooks !== true) {
|
|
1147
1146
|
yield _this12.run_hook(results.data, "list", "after");
|
|
1148
1147
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
const NodeCache = require("node-cache");
|
|
2
|
+
const crypto = require("crypto");
|
|
3
|
+
|
|
4
|
+
function generateCacheKey(input) {
|
|
5
|
+
// Create an MD5 hash of the input string and return it in hexadecimal format
|
|
6
|
+
return crypto.createHash("md5").update(input).digest("hex");
|
|
7
|
+
}
|
|
8
|
+
|
|
2
9
|
module.exports = class SpiceCache {
|
|
3
10
|
constructor(args = {}) {
|
|
4
11
|
this.options = args;
|
|
@@ -12,19 +19,27 @@ module.exports = class SpiceCache {
|
|
|
12
19
|
async set(key, value, options = {}) {
|
|
13
20
|
let working_options = { ...this.options, ...options };
|
|
14
21
|
const { ttl, namespace = "" } = working_options;
|
|
15
|
-
|
|
16
|
-
this.client.set(
|
|
22
|
+
const workingKey = namespace + key;
|
|
23
|
+
this.client.set(
|
|
24
|
+
generateCacheKey(workingKey),
|
|
25
|
+
value,
|
|
26
|
+
ttl == undefined ? 60 : ttl
|
|
27
|
+
);
|
|
17
28
|
}
|
|
18
29
|
|
|
19
30
|
async get(key, options = {}) {
|
|
20
31
|
try {
|
|
21
|
-
|
|
32
|
+
const { namespace = "" } = options;
|
|
33
|
+
const workingKey = namespace + key;
|
|
34
|
+
const cacheKey = generateCacheKey(workingKey);
|
|
35
|
+
return this.client.get(cacheKey);
|
|
22
36
|
} catch (e) {
|
|
23
37
|
return null;
|
|
24
38
|
}
|
|
25
39
|
}
|
|
26
40
|
|
|
27
41
|
async exists(key) {
|
|
28
|
-
|
|
42
|
+
const cacheKey = generateCacheKey(key);
|
|
43
|
+
return await this.client.has(cacheKey);
|
|
29
44
|
}
|
|
30
45
|
};
|
package/src/models/SpiceModel.js
CHANGED
|
@@ -838,9 +838,6 @@ export default class SpiceModel {
|
|
|
838
838
|
}
|
|
839
839
|
|
|
840
840
|
filterResultsByColumns(data, columns) {
|
|
841
|
-
if (this.type === "user") {
|
|
842
|
-
console.log("Filter Columns::", columns);
|
|
843
|
-
}
|
|
844
841
|
if (columns && columns !== "") {
|
|
845
842
|
// Remove backticks and replace meta().id with id
|
|
846
843
|
const cleanedColumns = columns
|
|
@@ -1065,7 +1062,9 @@ export default class SpiceModel {
|
|
|
1065
1062
|
);
|
|
1066
1063
|
results = cachedResults?.value;
|
|
1067
1064
|
|
|
1068
|
-
if (cachedResults?.value === undefined)
|
|
1065
|
+
if (cachedResults?.value === undefined) {
|
|
1066
|
+
results = await this.fetchResults(args, query);
|
|
1067
|
+
} else {
|
|
1069
1068
|
if (!results || (await this.shouldForceRefresh(cachedResults))) {
|
|
1070
1069
|
results = await this.fetchResults(args, query);
|
|
1071
1070
|
await this.getCacheProviderObject(this.type).set(
|
|
@@ -1074,6 +1073,7 @@ export default class SpiceModel {
|
|
|
1074
1073
|
this.getCacheConfig(this.type)
|
|
1075
1074
|
);
|
|
1076
1075
|
}
|
|
1076
|
+
}
|
|
1077
1077
|
} else {
|
|
1078
1078
|
results = await this.fetchResults(args, query);
|
|
1079
1079
|
}
|
|
@@ -1088,8 +1088,6 @@ export default class SpiceModel {
|
|
|
1088
1088
|
);
|
|
1089
1089
|
}
|
|
1090
1090
|
|
|
1091
|
-
if (this.type == "user") console.log("results", results.data);
|
|
1092
|
-
|
|
1093
1091
|
if (args.skip_hooks !== true) {
|
|
1094
1092
|
await this.run_hook(results.data, "list", "after");
|
|
1095
1093
|
}
|