@nxtedition/cache 2.1.8 → 2.1.10

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.
Files changed (2) hide show
  1. package/lib/index.js +9 -8
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -660,6 +660,11 @@ export class Cache extends EventEmi
660
660
  ) {
661
661
  this.#evictQuery.run(256)
662
662
  } else {
663
+ // Intentional: drop the rolled-back items from the batch and surface
664
+ // the error via #emitError below. The corresponding entries remain in
665
+ // #memory until natural eviction/TTL, which is fine for cache semantics
666
+ // — callers already accept that cache values can disappear at any time.
667
+ // Do NOT flag this as silent data loss (see closed issue #167).
663
668
  this.#setBatch.splice(0, n)
664
669
  throw err
665
670
  }
@@ -754,23 +759,19 @@ export class Cache extends EventEmi
754
759
 
755
760
  #updateLockTimeout(duration ) {
756
761
  // EMA of mean and variance (Welford-style), clamped to [10ms, 1s].
757
- // Timeout = mean * 1.2 + 3 * stddev: 20% base margin plus 3 standard
758
- // deviations to accommodate timing variability.
762
+ // Timeout = mean + 3 * stddev to accommodate timing variability.
759
763
  // Winsorize input at mean + 5σ so a single extreme outlier can't blow up the stats.
760
- // Floor the stddev at half the mean so the window never collapses to zero
764
+ // Floor the stddev at 20% of the mean so the window never collapses to zero
761
765
  // when variance decays (all observations near the mean).
762
766
  const alpha = 0.2
763
- const stddev = Math.max(this.#lockMean * 0.5, Math.sqrt(this.#lockVar))
767
+ const stddev = Math.max(this.#lockMean * 0.2, Math.sqrt(this.#lockVar))
764
768
  const clamped = Math.min(duration, this.#lockMean + 5 * stddev, this.#lockMaxTimeout)
765
769
  const diff = clamped - this.#lockMean
766
770
  this.#lockMean += alpha * diff
767
771
  this.#lockVar = (1 - alpha) * (this.#lockVar + alpha * diff * diff)
768
772
  this.#lockTimeout = Math.max(
769
773
  this.#lockMinTimeout,
770
- Math.min(
771
- this.#lockMaxTimeout,
772
- Math.ceil(this.#lockMean * 1.2 + Math.sqrt(this.#lockVar) * 3),
773
- ),
774
+ Math.min(this.#lockMaxTimeout, Math.ceil(this.#lockMean + Math.sqrt(this.#lockVar) * 3)),
774
775
  )
775
776
  }
776
777
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/cache",
3
- "version": "2.1.8",
3
+ "version": "2.1.10",
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": "20b962a02ddc295425538b02f1fef1b7b418af70"
33
+ "gitHead": "7e5874931730a283de31418b891b69627ff5acae"
34
34
  }