@nxtedition/cache 2.1.8 → 2.1.9
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/lib/index.js +4 -8
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -754,23 +754,19 @@ export class Cache extends EventEmi
|
|
|
754
754
|
|
|
755
755
|
#updateLockTimeout(duration ) {
|
|
756
756
|
// EMA of mean and variance (Welford-style), clamped to [10ms, 1s].
|
|
757
|
-
// Timeout = mean
|
|
758
|
-
// deviations to accommodate timing variability.
|
|
757
|
+
// Timeout = mean + 3 * stddev to accommodate timing variability.
|
|
759
758
|
// Winsorize input at mean + 5σ so a single extreme outlier can't blow up the stats.
|
|
760
|
-
// Floor the stddev at
|
|
759
|
+
// Floor the stddev at 20% of the mean so the window never collapses to zero
|
|
761
760
|
// when variance decays (all observations near the mean).
|
|
762
761
|
const alpha = 0.2
|
|
763
|
-
const stddev = Math.max(this.#lockMean * 0.
|
|
762
|
+
const stddev = Math.max(this.#lockMean * 0.2, Math.sqrt(this.#lockVar))
|
|
764
763
|
const clamped = Math.min(duration, this.#lockMean + 5 * stddev, this.#lockMaxTimeout)
|
|
765
764
|
const diff = clamped - this.#lockMean
|
|
766
765
|
this.#lockMean += alpha * diff
|
|
767
766
|
this.#lockVar = (1 - alpha) * (this.#lockVar + alpha * diff * diff)
|
|
768
767
|
this.#lockTimeout = Math.max(
|
|
769
768
|
this.#lockMinTimeout,
|
|
770
|
-
Math.min(
|
|
771
|
-
this.#lockMaxTimeout,
|
|
772
|
-
Math.ceil(this.#lockMean * 1.2 + Math.sqrt(this.#lockVar) * 3),
|
|
773
|
-
),
|
|
769
|
+
Math.min(this.#lockMaxTimeout, Math.ceil(this.#lockMean + Math.sqrt(this.#lockVar) * 3)),
|
|
774
770
|
)
|
|
775
771
|
}
|
|
776
772
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/cache",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"tsd": "^0.33.0",
|
|
31
31
|
"typescript": "^5.9.3"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "0bc928c692badb55bdf3c6928eea7742b8e17732"
|
|
34
34
|
}
|