@warlock.js/cache 5.6.0 → 5.7.0

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/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ All notable changes to `@warlock.js/cache` are documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
6
6
 
7
+ ## 5.7.0 - 2026-09-11
8
+
9
+ ### Fixed
10
+
11
+ - The in-memory cache driver's expiry sweep iterated `for...in` while deleting entries from the same object it was iterating, which could skip not-yet-visited keys and leave them cached past their TTL. It now snapshots entries first.
12
+
13
+ ### Changed
14
+
15
+ - Internal type-safety hardening elsewhere (similarity scoring, percentile calculation); no behaviour change.
16
+
7
17
  ## 5.5.0 - 2026-09-07
8
18
 
9
19
  ### Fixed
package/cjs/index.cjs CHANGED
@@ -183,7 +183,7 @@ var CacheMetricsCollector = class {
183
183
  };
184
184
  const sorted = [...samples].sort((a, b) => a - b);
185
185
  const pick = (quantile) => {
186
- return sorted[Math.min(sorted.length - 1, Math.floor(quantile * sorted.length))];
186
+ return sorted[Math.min(sorted.length - 1, Math.floor(quantile * sorted.length))] ?? 0;
187
187
  };
188
188
  return {
189
189
  p50: pick(.5),
@@ -453,6 +453,7 @@ function cosineSimilarity(a, b) {
453
453
  for (let i = 0; i < a.length; i++) {
454
454
  const x = a[i];
455
455
  const y = b[i];
456
+ if (x === void 0 || y === void 0) break;
456
457
  dot += x * y;
457
458
  normA += x * x;
458
459
  normB += y * y;
@@ -2859,8 +2860,8 @@ var MemoryCacheDriver = class extends BaseCacheDriver {
2859
2860
  if (this.cleanupInterval) clearInterval(this.cleanupInterval);
2860
2861
  this.cleanupInterval = setInterval(async () => {
2861
2862
  const now = Date.now();
2862
- for (const key in this.temporaryData) if (this.temporaryData[key].expiresAt <= now) {
2863
- await this.remove(this.temporaryData[key].key);
2863
+ for (const [key, entry] of Object.entries(this.temporaryData)) if (entry.expiresAt <= now) {
2864
+ await this.remove(entry.key);
2864
2865
  delete this.temporaryData[key];
2865
2866
  this.log("expired", key);
2866
2867
  await this.emit("expired", { key });