@smartico/public-api 0.0.201 → 0.0.202
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/NodeCache.d.ts +2 -2
- package/dist/index.js +23 -13
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +22 -13
- package/dist/index.modern.mjs.map +1 -1
- package/package.json +1 -1
- package/src/NodeCache.ts +18 -14
- package/src/OCache.ts +5 -0
package/dist/NodeCache.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -496,14 +496,17 @@ exports.SAWGameLayout = void 0;
|
|
|
496
496
|
|
|
497
497
|
var NodeCache = /*#__PURE__*/function () {
|
|
498
498
|
function NodeCache() {
|
|
499
|
-
|
|
500
|
-
|
|
499
|
+
var _this = this;
|
|
500
|
+
this.ttlChecker = void 0;
|
|
501
|
+
this.cache = {};
|
|
502
|
+
if (this.ttlChecker === undefined) {
|
|
503
|
+
this.ttlChecker = setInterval(function () {
|
|
501
504
|
var now = new Date().getTime();
|
|
502
|
-
for (var key in
|
|
503
|
-
if (
|
|
504
|
-
var o =
|
|
505
|
+
for (var key in _this.cache) {
|
|
506
|
+
if (_this.cache.hasOwnProperty(key)) {
|
|
507
|
+
var o = _this.cache[key];
|
|
505
508
|
if (o.ttl < now) {
|
|
506
|
-
delete
|
|
509
|
+
delete _this.cache[key];
|
|
507
510
|
}
|
|
508
511
|
}
|
|
509
512
|
}
|
|
@@ -512,7 +515,7 @@ var NodeCache = /*#__PURE__*/function () {
|
|
|
512
515
|
}
|
|
513
516
|
var _proto = NodeCache.prototype;
|
|
514
517
|
_proto.get = function get(key) {
|
|
515
|
-
var o =
|
|
518
|
+
var o = this.cache[key];
|
|
516
519
|
if (o !== undefined && o.ttl > new Date().getTime()) {
|
|
517
520
|
return o.value;
|
|
518
521
|
}
|
|
@@ -521,23 +524,25 @@ var NodeCache = /*#__PURE__*/function () {
|
|
|
521
524
|
if (ttlSeconds === void 0) {
|
|
522
525
|
ttlSeconds = 60;
|
|
523
526
|
}
|
|
524
|
-
|
|
527
|
+
this.cache[key] = {
|
|
525
528
|
value: value,
|
|
526
529
|
ttl: new Date().getTime() + ttlSeconds * 1000
|
|
527
530
|
};
|
|
528
531
|
};
|
|
529
532
|
_proto.remove = function remove(key) {
|
|
530
|
-
if (
|
|
531
|
-
delete
|
|
533
|
+
if (this.cache.hasOwnProperty(key)) {
|
|
534
|
+
delete this.cache[key];
|
|
532
535
|
}
|
|
533
536
|
};
|
|
534
537
|
_proto.flushAll = function flushAll() {
|
|
535
|
-
|
|
538
|
+
this.cache = {};
|
|
539
|
+
if (this.ttlChecker) {
|
|
540
|
+
clearInterval(this.ttlChecker);
|
|
541
|
+
this.ttlChecker = undefined;
|
|
542
|
+
}
|
|
536
543
|
};
|
|
537
544
|
return NodeCache;
|
|
538
545
|
}();
|
|
539
|
-
NodeCache.ttlChecker = void 0;
|
|
540
|
-
NodeCache.cache = {};
|
|
541
546
|
|
|
542
547
|
exports.ECacheContext = void 0;
|
|
543
548
|
(function (ECacheContext) {
|
|
@@ -616,6 +621,11 @@ var OCache = /*#__PURE__*/function () {
|
|
|
616
621
|
OCache.clearAll = function clearAll() {
|
|
617
622
|
try {
|
|
618
623
|
var _this3 = this;
|
|
624
|
+
for (var cacheContext in _this3.cache) {
|
|
625
|
+
if (_this3.cache.hasOwnProperty(cacheContext)) {
|
|
626
|
+
_this3.cache[cacheContext].flushAll();
|
|
627
|
+
}
|
|
628
|
+
}
|
|
619
629
|
_this3.cache = {};
|
|
620
630
|
return Promise.resolve();
|
|
621
631
|
} catch (e) {
|