@warlock.js/cache 5.53.0 → 5.54.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 +19 -0
- package/cjs/index.cjs +158 -7
- package/cjs/index.cjs.map +1 -1
- package/esm/cache-manager.d.mts +12 -0
- package/esm/cache-manager.d.mts.map +1 -1
- package/esm/cache-manager.mjs +18 -0
- package/esm/cache-manager.mjs.map +1 -1
- package/esm/cached/auto-key.mjs.map +1 -1
- package/esm/cached/cached.mjs.map +1 -1
- package/esm/cached/normalize-args.mjs.map +1 -1
- package/esm/drivers/base-cache-driver.d.mts +11 -0
- package/esm/drivers/base-cache-driver.d.mts.map +1 -1
- package/esm/drivers/base-cache-driver.mjs +43 -6
- package/esm/drivers/base-cache-driver.mjs.map +1 -1
- package/esm/drivers/clone-value.mjs.map +1 -1
- package/esm/drivers/file-cache-driver.d.mts +7 -0
- package/esm/drivers/file-cache-driver.d.mts.map +1 -1
- package/esm/drivers/file-cache-driver.mjs +14 -0
- package/esm/drivers/file-cache-driver.mjs.map +1 -1
- package/esm/drivers/in-memory-tag-index.mjs.map +1 -1
- package/esm/drivers/lru-memory-cache-driver.d.mts +4 -0
- package/esm/drivers/lru-memory-cache-driver.d.mts.map +1 -1
- package/esm/drivers/lru-memory-cache-driver.mjs +13 -0
- package/esm/drivers/lru-memory-cache-driver.mjs.map +1 -1
- package/esm/drivers/memory-cache-driver.d.mts +4 -0
- package/esm/drivers/memory-cache-driver.d.mts.map +1 -1
- package/esm/drivers/memory-cache-driver.mjs +13 -0
- package/esm/drivers/memory-cache-driver.mjs.map +1 -1
- package/esm/drivers/memory-extended-cache-driver.mjs.map +1 -1
- package/esm/drivers/mock-cache-driver.d.mts +4 -0
- package/esm/drivers/mock-cache-driver.d.mts.map +1 -1
- package/esm/drivers/mock-cache-driver.mjs +9 -0
- package/esm/drivers/mock-cache-driver.mjs.map +1 -1
- package/esm/drivers/null-cache-driver.d.mts +4 -0
- package/esm/drivers/null-cache-driver.d.mts.map +1 -1
- package/esm/drivers/null-cache-driver.mjs +6 -0
- package/esm/drivers/null-cache-driver.mjs.map +1 -1
- package/esm/drivers/pg-cache-driver.d.mts +4 -0
- package/esm/drivers/pg-cache-driver.d.mts.map +1 -1
- package/esm/drivers/pg-cache-driver.mjs +8 -0
- package/esm/drivers/pg-cache-driver.mjs.map +1 -1
- package/esm/drivers/redis-cache-driver.d.mts +7 -0
- package/esm/drivers/redis-cache-driver.d.mts.map +1 -1
- package/esm/drivers/redis-cache-driver.mjs +18 -0
- package/esm/drivers/redis-cache-driver.mjs.map +1 -1
- package/esm/idempotent.mjs.map +1 -1
- package/esm/index.d.mts +2 -2
- package/esm/index.mjs +2 -2
- package/esm/list/memory-cache-list.mjs.map +1 -1
- package/esm/metrics.mjs.map +1 -1
- package/esm/scoped-cache.d.mts.map +1 -1
- package/esm/scoped-cache.mjs +5 -2
- package/esm/scoped-cache.mjs.map +1 -1
- package/esm/structures/bloom-filter.mjs.map +1 -1
- package/esm/structures/cuckoo-filter.mjs.map +1 -1
- package/esm/structures/frequency-tracker.mjs.map +1 -1
- package/esm/structures/hash.mjs.map +1 -1
- package/esm/structures/hyperloglog.mjs.map +1 -1
- package/esm/structures/memory-structures-backend.mjs.map +1 -1
- package/esm/structures/redis-structures-backend.mjs.map +1 -1
- package/esm/structures/sizing.mjs.map +1 -1
- package/esm/structures/structures.mjs.map +1 -1
- package/esm/structures/types.mjs.map +1 -1
- package/esm/structures/unique-counter.mjs.map +1 -1
- package/esm/tag-sample.mjs.map +1 -1
- package/esm/tagged-cache.mjs.map +1 -1
- package/esm/tagged-scoped-cache.mjs.map +1 -1
- package/esm/types.d.mts +53 -0
- package/esm/types.d.mts.map +1 -1
- package/esm/types.mjs.map +1 -1
- package/esm/utils.d.mts +6 -0
- package/esm/utils.d.mts.map +1 -1
- package/esm/utils.mjs +13 -1
- package/esm/utils.mjs.map +1 -1
- package/llms-full.txt +6 -0
- package/package.json +4 -4
- package/skills/cache-basics/SKILL.md +1 -0
- package/skills/configure-set-options/SKILL.md +2 -0
- package/skills/use-cache-namespace/SKILL.md +1 -0
- package/skills/use-cache-similarity/SKILL.md +1 -0
- package/skills/use-swr/SKILL.md +1 -0
package/llms-full.txt
CHANGED
|
@@ -288,6 +288,7 @@ const user = await cache.remember("user.1", "1h", async () => db.users.find(1));
|
|
|
288
288
|
- Don't run `cache.similar()` against memory drivers in production with large datasets — O(N) brute force.
|
|
289
289
|
- Don't auto-migrate the `pg` table from app code. The driver exposes `driver.schema()` returning DDL.
|
|
290
290
|
- Don't switch embedders without re-embedding the entire vector index.
|
|
291
|
+
- `has(key)` uses the driver `exists()` (no value read) and emits `hit` / `miss` with the key only, without `value`.
|
|
291
292
|
|
|
292
293
|
|
|
293
294
|
## configure-pg-cache `@warlock.js/cache/skills/configure-pg-cache/SKILL.md`
|
|
@@ -515,6 +516,8 @@ await cache.set("k", v, 3600); // seconds
|
|
|
515
516
|
await cache.set("k", v, undefined); // same as no TTL
|
|
516
517
|
```
|
|
517
518
|
|
|
519
|
+
- `ttlJitter: <percent>` spreads the TTL by up to that many percent either way per write (`{ ttl: "1h", ttlJitter: 10 }` expires in 54-66 minutes) so entries written together do not expire together; ignored for `expiresAt` / `Infinity`; also accepted by `remember()` and `swr()` options. `applyTtlJitter(ttl, percent, expiresAt?)` is the helper that computes it.
|
|
520
|
+
|
|
518
521
|
|
|
519
522
|
## handle-cache-errors `@warlock.js/cache/skills/handle-cache-errors/SKILL.md`
|
|
520
523
|
|
|
@@ -1491,6 +1494,7 @@ await chat.set("messages.10", msg); // chats.<id>.messages.10, 30d, user.<userId
|
|
|
1491
1494
|
await chat.set("draft", d, { ttl: "1h" }); // per-call ttl wins
|
|
1492
1495
|
await chat.tags(["unread"]).set("ping", p); // tags merge: user.<userId> + unread
|
|
1493
1496
|
await chat.clear(); // sugar for removeNamespace
|
|
1497
|
+
const keys = await cache.listKeys("chats.7"); // live keys under a prefix, ready for get() / remove(); optional on custom drivers
|
|
1494
1498
|
```
|
|
1495
1499
|
|
|
1496
1500
|
Scopes are pure views — same connection, same driver, no extra state. Per-call options always win over scope defaults; tags merge additively.
|
|
@@ -1658,6 +1662,7 @@ See the `configure-pg-cache` topic.
|
|
|
1658
1662
|
- Don't mix vector dimensions in the same driver — re-embed when models change.
|
|
1659
1663
|
- Don't expect `similar()` to surface a missing vector (`set` without the `vector` option). Plain KV entries stay out of the similarity index.
|
|
1660
1664
|
- Don't use `topK: 0` or negative — `pg` rejects with `CacheConfigurationError`; memory drivers return `[]` but it's a code smell.
|
|
1665
|
+
- `filter: ({ key, value }) => boolean` runs before `threshold` / `topK`, so `topK` counts in-scope entries only (one query). Honoured by the memory, LRU and memory-extended drivers; `pg` ignores it, so re-check hits when you need a guarantee. A `cache.namespace()` scope passes its prefix as the filter.
|
|
1661
1666
|
|
|
1662
1667
|
|
|
1663
1668
|
## use-cache-structures `@warlock.js/cache/skills/use-cache-structures/SKILL.md`
|
|
@@ -2197,5 +2202,6 @@ await feed.swr("home", { freshTtl: "30s", staleTtl: "10m", tags: ["computed"] },
|
|
|
2197
2202
|
- Don't pick `freshTtl` to be the _same_ as `staleTtl` thinking it disables the stale window — that throws. Pick a tight `freshTtl` and wider `staleTtl` that reflects how stale your product can tolerate being.
|
|
2198
2203
|
- Don't ignore `error` events. A persistent stream of refresh failures means upstream is broken and the cache is masking it.
|
|
2199
2204
|
- Don't reach for SWR on the null driver — it caches nothing, so SWR always blocks.
|
|
2205
|
+
- `failSafe: true` makes a stale-window caller wait for the refresh (callers of one key share it) and return the stale value when the callback throws; the failure is logged and emitted as an `error` event. Default (off): stale value at once, refresh in the background.
|
|
2200
2206
|
|
|
2201
2207
|
|
package/package.json
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
"environment": "server"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@warlock.js/fs": "5.
|
|
9
|
-
"@mongez/reinforcements": "^4.0
|
|
10
|
-
"@warlock.js/logger": "5.
|
|
8
|
+
"@warlock.js/fs": "5.54.0",
|
|
9
|
+
"@mongez/reinforcements": "^4.1.0",
|
|
10
|
+
"@warlock.js/logger": "5.54.0",
|
|
11
11
|
"ms": "^2.1.3"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
],
|
|
48
48
|
"author": "hassanzohdy",
|
|
49
49
|
"license": "MIT",
|
|
50
|
-
"version": "5.
|
|
50
|
+
"version": "5.54.0",
|
|
51
51
|
"main": "./cjs/index.cjs",
|
|
52
52
|
"module": "./esm/index.mjs",
|
|
53
53
|
"types": "./esm/index.d.mts",
|
|
@@ -125,3 +125,4 @@ const user = await cache.remember("user.1", "1h", async () => db.users.find(1));
|
|
|
125
125
|
- Don't run `cache.similar()` against memory drivers in production with large datasets — O(N) brute force.
|
|
126
126
|
- Don't auto-migrate the `pg` table from app code. The driver exposes `driver.schema()` returning DDL.
|
|
127
127
|
- Don't switch embedders without re-embedding the entire vector index.
|
|
128
|
+
- `has(key)` uses the driver `exists()` (no value read) and emits `hit` / `miss` with the key only, without `value`.
|
|
@@ -100,3 +100,5 @@ await cache.set("k", v); // no TTL — driver default
|
|
|
100
100
|
await cache.set("k", v, 3600); // seconds
|
|
101
101
|
await cache.set("k", v, undefined); // same as no TTL
|
|
102
102
|
```
|
|
103
|
+
|
|
104
|
+
- `ttlJitter: <percent>` spreads the TTL by up to that many percent either way per write (`{ ttl: "1h", ttlJitter: 10 }` expires in 54-66 minutes) so entries written together do not expire together; ignored for `expiresAt` / `Infinity`; also accepted by `remember()` and `swr()` options. `applyTtlJitter(ttl, percent, expiresAt?)` is the helper that computes it.
|
|
@@ -16,6 +16,7 @@ await chat.set("messages.10", msg); // chats.<id>.messages.10, 30d, user.<userId
|
|
|
16
16
|
await chat.set("draft", d, { ttl: "1h" }); // per-call ttl wins
|
|
17
17
|
await chat.tags(["unread"]).set("ping", p); // tags merge: user.<userId> + unread
|
|
18
18
|
await chat.clear(); // sugar for removeNamespace
|
|
19
|
+
const keys = await cache.listKeys("chats.7"); // live keys under a prefix, ready for get() / remove(); optional on custom drivers
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
Scopes are pure views — same connection, same driver, no extra state. Per-call options always win over scope defaults; tags merge additively.
|
|
@@ -92,3 +92,4 @@ See the `configure-pg-cache` topic.
|
|
|
92
92
|
- Don't mix vector dimensions in the same driver — re-embed when models change.
|
|
93
93
|
- Don't expect `similar()` to surface a missing vector (`set` without the `vector` option). Plain KV entries stay out of the similarity index.
|
|
94
94
|
- Don't use `topK: 0` or negative — `pg` rejects with `CacheConfigurationError`; memory drivers return `[]` but it's a code smell.
|
|
95
|
+
- `filter: ({ key, value }) => boolean` runs before `threshold` / `topK`, so `topK` counts in-scope entries only (one query). Honoured by the memory, LRU and memory-extended drivers; `pg` ignores it, so re-check hits when you need a guarantee. A `cache.namespace()` scope passes its prefix as the filter.
|
package/skills/use-swr/SKILL.md
CHANGED
|
@@ -98,3 +98,4 @@ await feed.swr("home", { freshTtl: "30s", staleTtl: "10m", tags: ["computed"] },
|
|
|
98
98
|
- Don't pick `freshTtl` to be the _same_ as `staleTtl` thinking it disables the stale window — that throws. Pick a tight `freshTtl` and wider `staleTtl` that reflects how stale your product can tolerate being.
|
|
99
99
|
- Don't ignore `error` events. A persistent stream of refresh failures means upstream is broken and the cache is masking it.
|
|
100
100
|
- Don't reach for SWR on the null driver — it caches nothing, so SWR always blocks.
|
|
101
|
+
- `failSafe: true` makes a stale-window caller wait for the refresh (callers of one key share it) and return the stale value when the callback throws; the failure is logged and emitted as an `error` event. Default (off): stale value at once, refresh in the background.
|