spice-js 2.6.55 → 2.6.56
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
|
|
|
@@ -542,6 +542,7 @@ class SpiceModel {
|
|
|
542
542
|
}
|
|
543
543
|
|
|
544
544
|
if (monitor_record.time > (response == null ? void 0 : response.time)) {
|
|
545
|
+
if (_this3.type == "resourcedetail") console.log("Will Force Refresh");
|
|
545
546
|
return true;
|
|
546
547
|
}
|
|
547
548
|
|
|
@@ -929,10 +930,6 @@ class SpiceModel {
|
|
|
929
930
|
}
|
|
930
931
|
|
|
931
932
|
filterResultsByColumns(data, columns) {
|
|
932
|
-
if (this.type === "user") {
|
|
933
|
-
console.log("Filter Columns::", columns);
|
|
934
|
-
}
|
|
935
|
-
|
|
936
933
|
if (columns && columns !== "") {
|
|
937
934
|
// Remove backticks and replace meta().id with id
|
|
938
935
|
var cleanedColumns = columns.replace(/`/g, "").replace(/meta\(\)\.id/g, "id"); // Process each column by splitting on comma and trimming
|
|
@@ -1126,12 +1123,17 @@ class SpiceModel {
|
|
|
1126
1123
|
if (_this12.shouldUseCache(_this12.type)) {
|
|
1127
1124
|
var cachedResults = yield _this12.getCacheProviderObject(_this12.type).get(cacheKey);
|
|
1128
1125
|
results = cachedResults == null ? void 0 : cachedResults.value;
|
|
1129
|
-
|
|
1126
|
+
|
|
1127
|
+
if ((cachedResults == null ? void 0 : cachedResults.value) === undefined) {
|
|
1130
1128
|
results = yield _this12.fetchResults(args, query);
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1129
|
+
} else {
|
|
1130
|
+
if (!results || (yield _this12.shouldForceRefresh(cachedResults))) {
|
|
1131
|
+
results = yield _this12.fetchResults(args, query);
|
|
1132
|
+
yield _this12.getCacheProviderObject(_this12.type).set(cacheKey, {
|
|
1133
|
+
value: results,
|
|
1134
|
+
time: new Date().getTime()
|
|
1135
|
+
}, _this12.getCacheConfig(_this12.type));
|
|
1136
|
+
}
|
|
1135
1137
|
}
|
|
1136
1138
|
} else {
|
|
1137
1139
|
results = yield _this12.fetchResults(args, query);
|
|
@@ -1141,8 +1143,6 @@ class SpiceModel {
|
|
|
1141
1143
|
results.data = yield _this12.do_serialize(results.data, "read", {}, args, (yield _this12.propsToBeRemoved(results.data)));
|
|
1142
1144
|
}
|
|
1143
1145
|
|
|
1144
|
-
if (_this12.type == "user") console.log("results", results.data);
|
|
1145
|
-
|
|
1146
1146
|
if (args.skip_hooks !== true) {
|
|
1147
1147
|
yield _this12.run_hook(results.data, "list", "after");
|
|
1148
1148
|
}
|
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
|
@@ -468,6 +468,7 @@ export default class SpiceModel {
|
|
|
468
468
|
return false;
|
|
469
469
|
}
|
|
470
470
|
if (monitor_record.time > response?.time) {
|
|
471
|
+
if (this.type == "resourcedetail") console.log("Will Force Refresh");
|
|
471
472
|
return true;
|
|
472
473
|
}
|
|
473
474
|
return false;
|
|
@@ -838,9 +839,6 @@ export default class SpiceModel {
|
|
|
838
839
|
}
|
|
839
840
|
|
|
840
841
|
filterResultsByColumns(data, columns) {
|
|
841
|
-
if (this.type === "user") {
|
|
842
|
-
console.log("Filter Columns::", columns);
|
|
843
|
-
}
|
|
844
842
|
if (columns && columns !== "") {
|
|
845
843
|
// Remove backticks and replace meta().id with id
|
|
846
844
|
const cleanedColumns = columns
|
|
@@ -1065,7 +1063,9 @@ export default class SpiceModel {
|
|
|
1065
1063
|
);
|
|
1066
1064
|
results = cachedResults?.value;
|
|
1067
1065
|
|
|
1068
|
-
if (cachedResults?.value === undefined)
|
|
1066
|
+
if (cachedResults?.value === undefined) {
|
|
1067
|
+
results = await this.fetchResults(args, query);
|
|
1068
|
+
} else {
|
|
1069
1069
|
if (!results || (await this.shouldForceRefresh(cachedResults))) {
|
|
1070
1070
|
results = await this.fetchResults(args, query);
|
|
1071
1071
|
await this.getCacheProviderObject(this.type).set(
|
|
@@ -1074,6 +1074,7 @@ export default class SpiceModel {
|
|
|
1074
1074
|
this.getCacheConfig(this.type)
|
|
1075
1075
|
);
|
|
1076
1076
|
}
|
|
1077
|
+
}
|
|
1077
1078
|
} else {
|
|
1078
1079
|
results = await this.fetchResults(args, query);
|
|
1079
1080
|
}
|
|
@@ -1088,8 +1089,6 @@ export default class SpiceModel {
|
|
|
1088
1089
|
);
|
|
1089
1090
|
}
|
|
1090
1091
|
|
|
1091
|
-
if (this.type == "user") console.log("results", results.data);
|
|
1092
|
-
|
|
1093
1092
|
if (args.skip_hooks !== true) {
|
|
1094
1093
|
await this.run_hook(results.data, "list", "after");
|
|
1095
1094
|
}
|