redis-distributed-cache-tools 1.0.42 → 1.0.44
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 +19 -0
- package/package.json +1 -1
- package/dist/get-hot-key.function.d.ts +0 -1
- package/dist/get-hot-key.function.js +0 -10
- package/dist/get-jitter.function.d.ts +0 -1
- package/dist/get-jitter.function.js +0 -9
- package/dist/should-recompute.function.d.ts +0 -1
- package/dist/should-recompute.function.js +0 -22
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./get-hot-key.function"), exports);
|
|
18
|
+
__exportStar(require("./get-jitter.function"), exports);
|
|
19
|
+
__exportStar(require("./should-recompute.function"), exports);
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getHotKey(key: string, numberOfSeperate?: number): string;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHotKey = void 0;
|
|
4
|
-
function getHotKey(key, numberOfSeperate) {
|
|
5
|
-
if (numberOfSeperate === undefined || numberOfSeperate === 0) {
|
|
6
|
-
return key;
|
|
7
|
-
}
|
|
8
|
-
return `${Math.floor(Math.random() * numberOfSeperate)}:${key}`;
|
|
9
|
-
}
|
|
10
|
-
exports.getHotKey = getHotKey;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getJitter(minutes: number, jitter: number): number;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getJitter = void 0;
|
|
4
|
-
function getJitter(minutes, jitter) {
|
|
5
|
-
const max = minutes * 60;
|
|
6
|
-
const min = minutes * (1 - jitter) * 60;
|
|
7
|
-
return Math.floor(Math.random() * (max - min) + min);
|
|
8
|
-
}
|
|
9
|
-
exports.getJitter = getJitter;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function shouldRecompute(lastDuration: number, keyTtlSeconds: number, maxEarlyRecomputeSeconds?: number, beta?: number): boolean;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shouldRecompute = void 0;
|
|
4
|
-
function shouldRecompute(lastDuration, keyTtlSeconds, maxEarlyRecomputeSeconds = 0, beta = 1) {
|
|
5
|
-
if (keyTtlSeconds < 1 || lastDuration < 1) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
const delta = lastDuration;
|
|
9
|
-
const random = Math.random();
|
|
10
|
-
const xfetch = (() => {
|
|
11
|
-
const recomputeSeconds = delta * beta * Math.log(random);
|
|
12
|
-
if (maxEarlyRecomputeSeconds > 0 && recomputeSeconds > -maxEarlyRecomputeSeconds) {
|
|
13
|
-
return Math.random() * -maxEarlyRecomputeSeconds;
|
|
14
|
-
}
|
|
15
|
-
return recomputeSeconds;
|
|
16
|
-
})();
|
|
17
|
-
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
|
|
18
|
-
const cacheExpireAt = currentTimestampInSeconds + keyTtlSeconds;
|
|
19
|
-
const isEarlyRecomputeRequired = currentTimestampInSeconds - xfetch >= cacheExpireAt;
|
|
20
|
-
return isEarlyRecomputeRequired;
|
|
21
|
-
}
|
|
22
|
-
exports.shouldRecompute = shouldRecompute;
|