tricache 0.5.0 → 0.5.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.
- package/README.md +18 -0
- package/dist/index.cjs +518 -112
- package/dist/index.d.cts +152 -8
- package/dist/index.d.ts +1310 -18
- package/dist/index.js +3131 -25
- package/package.json +11 -10
- package/src/cache-service.ts +197 -44
- package/src/disk-tier.ts +263 -25
- package/src/encryption.ts +14 -12
- package/src/smart-memory-cache.ts +152 -13
- package/src/types.ts +37 -0
- package/src/wasm/bloom-filter-wasm.ts +5 -21
- package/dist/cache-service.d.ts +0 -366
- package/dist/cache-service.d.ts.map +0 -1
- package/dist/cache-service.js +0 -1494
- package/dist/cache-service.js.map +0 -1
- package/dist/disk-tier.d.ts +0 -83
- package/dist/disk-tier.d.ts.map +0 -1
- package/dist/disk-tier.js +0 -324
- package/dist/disk-tier.js.map +0 -1
- package/dist/encryption.d.ts +0 -88
- package/dist/encryption.d.ts.map +0 -1
- package/dist/encryption.js +0 -371
- package/dist/encryption.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/smart-memory-cache.d.ts +0 -178
- package/dist/smart-memory-cache.d.ts.map +0 -1
- package/dist/smart-memory-cache.js +0 -753
- package/dist/smart-memory-cache.js.map +0 -1
- package/dist/types.d.ts +0 -428
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -20
- package/dist/types.js.map +0 -1
- package/dist/wasm/bloom-filter-wasm.d.ts +0 -29
- package/dist/wasm/bloom-filter-wasm.d.ts.map +0 -1
- package/dist/wasm/bloom-filter-wasm.js +0 -99
- package/dist/wasm/bloom-filter-wasm.js.map +0 -1
package/README.md
CHANGED
|
@@ -48,6 +48,9 @@ tricache is an extremely fast three-tier Node.js cache library. It serves warm r
|
|
|
48
48
|
| **XFetch probabilistic early expiry** | Probabilistic background recompute keyed to last fetch duration and `xfetchBeta` — optimal protection against expiry spikes under load |
|
|
49
49
|
| **`hotKeys(n)`** | Returns top N keys by Count-Min Sketch access frequency with size — no full Map scan |
|
|
50
50
|
| **`dependsOn` cascade invalidation** | Tag entries with parent keys; deleting a parent automatically evicts all declared dependents from L1 |
|
|
51
|
+
| **`onHit` / `onMiss` callbacks** | Per-operation hit/miss hooks with tier info (`'l1'` \| `'disk'` \| `'l2'`) — no wait for the metrics interval |
|
|
52
|
+
| **`frozen` mode** | Dev-time mutation guard — `Object.freeze()` applied recursively to every L1 hit so accidental mutations throw immediately |
|
|
53
|
+
| **`tags` in `get()` opts** | Attach tags at read time; when `fetchFn` populates the entry on a miss the tags are registered automatically |
|
|
51
54
|
|
|
52
55
|
---
|
|
53
56
|
|
|
@@ -262,6 +265,20 @@ CacheService.create({
|
|
|
262
265
|
// ── Metrics callback ─────────────────────────────────────────────────
|
|
263
266
|
metricsIntervalMs: 60_000, // emit every 60 s (default)
|
|
264
267
|
onMetrics: (m) => myMonitoring.record(m), // optional push callback
|
|
268
|
+
|
|
269
|
+
// ── Per-operation hooks ───────────────────────────────────────────────
|
|
270
|
+
// onHit fires on every L1, disk, or L2 hit with the caller-facing key (no prefix)
|
|
271
|
+
// and the tier that served it. Lower latency than waiting for onMetrics.
|
|
272
|
+
onHit: (key, tier) => cloudwatch.putMetricData({ key, tier }),
|
|
273
|
+
|
|
274
|
+
// onMiss fires when all three tiers are exhausted — before fetchFn is called.
|
|
275
|
+
onMiss: (key) => cloudwatch.putMetricData({ key }),
|
|
276
|
+
|
|
277
|
+
// ── Development mutation guard ────────────────────────────────────────
|
|
278
|
+
// When true, every L1 hit value is deep-frozen before being returned.
|
|
279
|
+
// Mutation attempts throw TypeError immediately in development.
|
|
280
|
+
// Do NOT enable in production — deep-freezing large objects has measurable overhead.
|
|
281
|
+
frozen: process.env.NODE_ENV !== 'production',
|
|
265
282
|
});
|
|
266
283
|
```
|
|
267
284
|
|
|
@@ -309,6 +326,7 @@ Get from cache or call `fetchFn` on a miss. The inflight map ensures `fetchFn` f
|
|
|
309
326
|
| `opts.refreshAhead` | `number` | — | Fraction `(0, 1]` of TTL — triggers background recompute when `remaining ≤ ttl × (1 - refreshAhead)` |
|
|
310
327
|
| `opts.xfetchBeta` | `number` | — | XFetch β ≥ 0 — scales probabilistic early recompute by last fetch duration; higher = recompute earlier |
|
|
311
328
|
| `opts.notFoundTtl` | `number` | — | Per-call TTL in seconds for `null`/`undefined` results (overrides global `notFoundTtl`) |
|
|
329
|
+
| `opts.tags` | `string[]` | — | Tags to register when `fetchFn` populates the entry on a miss; no-op on L1/L2 hits where tags are already registered |
|
|
312
330
|
|
|
313
331
|
### `cache.set<T>(key, data, ttlSeconds?, priority?, opts?)` → `Promise<void>`
|
|
314
332
|
|