@warlock.js/cache 5.52.0 → 5.53.1

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 (64) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/cjs/index.cjs +528 -122
  3. package/cjs/index.cjs.map +1 -1
  4. package/esm/cached/auto-key.d.mts +3 -1
  5. package/esm/cached/auto-key.d.mts.map +1 -1
  6. package/esm/cached/auto-key.mjs +9 -4
  7. package/esm/cached/auto-key.mjs.map +1 -1
  8. package/esm/drivers/base-cache-driver.d.mts +40 -3
  9. package/esm/drivers/base-cache-driver.d.mts.map +1 -1
  10. package/esm/drivers/base-cache-driver.mjs +57 -7
  11. package/esm/drivers/base-cache-driver.mjs.map +1 -1
  12. package/esm/drivers/clone-value.mjs +17 -0
  13. package/esm/drivers/clone-value.mjs.map +1 -0
  14. package/esm/drivers/file-cache-driver.d.mts +40 -2
  15. package/esm/drivers/file-cache-driver.d.mts.map +1 -1
  16. package/esm/drivers/file-cache-driver.mjs +142 -18
  17. package/esm/drivers/file-cache-driver.mjs.map +1 -1
  18. package/esm/drivers/in-memory-tag-index.d.mts +5 -0
  19. package/esm/drivers/in-memory-tag-index.d.mts.map +1 -1
  20. package/esm/drivers/in-memory-tag-index.mjs +17 -0
  21. package/esm/drivers/in-memory-tag-index.mjs.map +1 -1
  22. package/esm/drivers/lru-memory-cache-driver.d.mts +18 -1
  23. package/esm/drivers/lru-memory-cache-driver.d.mts.map +1 -1
  24. package/esm/drivers/lru-memory-cache-driver.mjs +27 -2
  25. package/esm/drivers/lru-memory-cache-driver.mjs.map +1 -1
  26. package/esm/drivers/memory-cache-driver.d.mts +16 -1
  27. package/esm/drivers/memory-cache-driver.d.mts.map +1 -1
  28. package/esm/drivers/memory-cache-driver.mjs +34 -5
  29. package/esm/drivers/memory-cache-driver.mjs.map +1 -1
  30. package/esm/drivers/null-cache-driver.d.mts.map +1 -1
  31. package/esm/drivers/null-cache-driver.mjs +22 -12
  32. package/esm/drivers/null-cache-driver.mjs.map +1 -1
  33. package/esm/drivers/pg-cache-driver.d.mts +19 -0
  34. package/esm/drivers/pg-cache-driver.d.mts.map +1 -1
  35. package/esm/drivers/pg-cache-driver.mjs +52 -26
  36. package/esm/drivers/pg-cache-driver.mjs.map +1 -1
  37. package/esm/drivers/redis-cache-driver.d.mts +29 -0
  38. package/esm/drivers/redis-cache-driver.d.mts.map +1 -1
  39. package/esm/drivers/redis-cache-driver.mjs +70 -36
  40. package/esm/drivers/redis-cache-driver.mjs.map +1 -1
  41. package/esm/index.d.mts +2 -2
  42. package/esm/index.mjs +2 -2
  43. package/esm/tag-sample.mjs +16 -0
  44. package/esm/tag-sample.mjs.map +1 -0
  45. package/esm/tagged-cache.d.mts +15 -0
  46. package/esm/tagged-cache.d.mts.map +1 -1
  47. package/esm/tagged-cache.mjs +31 -10
  48. package/esm/tagged-cache.mjs.map +1 -1
  49. package/esm/types.d.mts +24 -5
  50. package/esm/types.d.mts.map +1 -1
  51. package/esm/types.mjs.map +1 -1
  52. package/esm/utils.d.mts +20 -1
  53. package/esm/utils.d.mts.map +1 -1
  54. package/esm/utils.mjs +42 -3
  55. package/esm/utils.mjs.map +1 -1
  56. package/llms-full.txt +9 -6
  57. package/llms.txt +1 -1
  58. package/package.json +3 -3
  59. package/skills/cache-basics/SKILL.md +1 -1
  60. package/skills/pick-cache-driver/SKILL.md +1 -1
  61. package/skills/use-cache-namespace/SKILL.md +1 -0
  62. package/skills/use-cache-tags/SKILL.md +1 -1
  63. package/skills/use-cache-utils/SKILL.md +4 -2
  64. package/skills/use-cached-hof/SKILL.md +1 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,42 @@ 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.53.0 - 2026-11-11
8
+
9
+ ### Upgrading
10
+
11
+ - Cache operation logging is off by default. Add `logging: true` to the cache configuration (or call `setLoggingState(true)`) to keep the per-operation lines.
12
+ - The `memory` and `memoryExtended` drivers evict past 10,000 entries. Set `maxSize: Infinity` to keep the previous unbounded behaviour, or a number that fits your data. Rate-limit counters and login lockouts kept in a memory cache can now be evicted by a flood of distinct keys: in production keep them in a shared store (`redis` or `pg`), or set `maxSize: Infinity` on that memory driver.
13
+ - Object cache keys whose values or property names contain `.`, `,`, `:`, `{`, `}`, `"`, `[`, `]` or `%`, and `cached()` calls with a `bigint` argument or an object key starting with `$` (such as `{ $gt: 5 }`), get a new key: those entries miss once and are written again.
14
+ - Tag pruning checks no longer emit `hit` / `miss` events or refresh an entry's recency or sliding TTL.
15
+ - The LRU driver's `swr()` returns a copy of the stored value; values it cannot copy (functions) fail there as they already did on `get()`.
16
+ - The file driver creates a `cache.json.guard` file in a key's directory for a few milliseconds while it removes an expired entry under contention.
17
+ - Removing an expired entry found by `get()` is awaited, so the `removed` event fires before `get()` resolves.
18
+
19
+ ### Security
20
+
21
+ - The LRU driver's `swr()` returned the stored object itself, so a caller that changed the result changed the cached value for every later reader. Each `swr()` reader gets a copy, as `get()` already did; a create-only write that conflicts also returns a copy of the existing value.
22
+ - The file driver's `lock()` and `set(..., { onConflict: "create" })` could be acquired by several callers at once when the previous entry had expired. An expired entry is now removed under a short-lived per-key guard file, so exactly one caller wins. Lock release (compare-and-delete) uses the same guard, so releasing a lock just as it expired never deletes the next holder's lock.
23
+ - Object cache keys are no longer ambiguous: `.`, `,`, `:`, `{`, `}`, `"`, `[`, `]` and `%` inside an object key's values and property names are percent-encoded, so `{ a: "b.c" }` and `{ a: "b", c: "" }` are different keys, and an own `__proto__` key is kept as data. Keys without those characters are unchanged.
24
+ - `cached()` auto-keys keep an own `__proto__` key of an argument as data, and an argument can no longer produce the same key as `undefined`, `NaN` or a `bigint` (object keys starting with `$` are escaped; a `bigint` gets its own marker).
25
+
26
+ ### Added
27
+
28
+ - `escapeCacheKeySegment(value)` percent-encodes the key separator characters, so a request-derived value (a tenant slug, a search term) stays one segment of a key or namespace: ``cache.namespace(`tenant.${escapeCacheKeySegment(slug)}`)``.
29
+ - Optional driver primitives `tagSample(tagKey, count)`, `exists(key)` and `removeMany(keys)`, used by tagged writes and tag invalidation. The Redis and Postgres drivers implement all three natively; a custom driver without them keeps the previous behaviour.
30
+
31
+ ### Changed
32
+
33
+ - Cache drivers no longer log every operation by default. Each get and set used to write two log lines (with email masking and redaction) at `info` / `success`; errors and connection failures are always logged.
34
+ - The `memory` and `memoryExtended` drivers keep at most 10,000 entries by default (`maxSize`), evicting the least recently used; they used to grow without bound, so keys built from request input could exhaust memory. Eviction no longer copies the whole key list on every write.
35
+ - Tagged writes no longer read the whole tag index and up to 20 full cached values: they sample up to 20 members (`SRANDMEMBER` on Redis, a database-side sample on Postgres) and check them with an existence test (`EXISTS`, `SELECT 1`) in one batch. Tag invalidation removes entries in batches (pipelined deletes on Redis, one `DELETE … = ANY(...)` per 500 keys on Postgres).
36
+ - Redis, Postgres and file `get()` no longer deep-clone a value that was just deserialized (it is already the caller's own copy).
37
+ - A plain Redis `set()` sends the SWR sidecar update together with the value, and `remove()` sends both deletes together: one round trip instead of two.
38
+
39
+ ### Fixed
40
+
41
+ - The file driver deletes an expired entry when it is read with a `globalPrefix` configured. The prefix used to be applied twice, so the directory stayed forever.
42
+
7
43
  ## 5.43.0 - 2026-11-01
8
44
 
9
45
  ### Added