tricache 0.1.0 → 0.2.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/README.md +210 -56
- package/dist/index.cjs +553 -63
- package/dist/index.d.cts +208 -8
- package/dist/index.d.ts +208 -8
- package/dist/index.js +553 -63
- package/package.json +9 -8
- package/src/cache-service.ts +367 -37
- package/src/disk-tier.ts +18 -2
- package/src/encryption.ts +69 -13
- package/src/index.ts +2 -0
- package/src/smart-memory-cache.ts +159 -18
- package/src/types.ts +75 -1
package/README.md
CHANGED
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TriCache
|
|
2
2
|
|
|
3
|
-
[](https://github.com/Kareem411/TriCache/actions/workflows/ci.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/tricache)
|
|
5
|
+
[](https://www.npmjs.com/package/tricache)
|
|
5
6
|
[](LICENSE)
|
|
6
7
|
[](https://nodejs.org)
|
|
7
8
|
[](https://www.typescriptlang.org)
|
|
9
|
+
[](BENCHMARKS.md)
|
|
10
|
+
[](BENCHMARKS.md)
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
tricache is an extremely fast three-tier Node.js cache library. It serves warm reads at **2.65 million operations per second** from a single thread — over 100× faster than a localhost Redis round-trip and below any network latency floor. When L1 fills, evicted entries spill to a local NVMe disk tier rather than being dropped, keeping hit rates high without unbounded RAM growth. Cache misses that reach L2 (Redis or Valkey) are automatically coalesced: no matter how many concurrent callers miss the same key, `fetchFn` fires exactly once. See the [performance section](#-performance) for full numbers. Stale-While-Revalidate, AES-256-GCM at-rest encryption, pub/sub fleet-wide invalidation, OOM guard, cold-start snapshots, and Prometheus metrics are also supported through optional configuration — with zero required fields to get started.
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
Request
|
|
15
|
-
│
|
|
16
|
-
▼
|
|
17
|
-
L1 — SmartMemoryCache (in-process RAM, 200 MB default, adaptive LFU×LRU×priority eviction)
|
|
18
|
-
│ miss
|
|
19
|
-
▼
|
|
20
|
-
L1.5 — DiskTier (NVMe spill, 500 MB default, 2–100 µs, holds evicted L1 entries)
|
|
21
|
-
│ miss
|
|
22
|
-
▼
|
|
23
|
-
L2 — Redis / Valkey (distributed, production-only by default, pub/sub invalidation)
|
|
24
|
-
│ miss
|
|
25
|
-
▼
|
|
26
|
-
fetchFn() (your database / API call — fires exactly once per key under load)
|
|
27
|
-
```
|
|
14
|
+
<img src="https://raw.githubusercontent.com/Kareem411/TriCache/master/public/SmartMemoryCache_DiskTier.jpeg" width="600" alt="tricache architecture" />
|
|
28
15
|
|
|
29
16
|
---
|
|
30
17
|
|
|
@@ -36,14 +23,19 @@ fetchFn() (your database / API call — fires exactly once per key
|
|
|
36
23
|
| **WASM Bloom filter** | 562-byte binary inlined as Base64 — O(k=7) guaranteed-miss detection, no filesystem access, pure-JS fallback |
|
|
37
24
|
| **msgpackr serialization** | All entries packed with msgpackr — uniform binary format, no JSON at any payload size |
|
|
38
25
|
| **Stale-While-Revalidate** | Serve stale instantly, revalidate in background — zero added latency on cache hit |
|
|
26
|
+
| **Stale-if-error** | Extend a stale entry's TTL when SWR revalidation fails — no errors served during upstream outages |
|
|
39
27
|
| **Thundering-herd prevention** | Inflight `Promise` registry — only one `fetchFn` call per key regardless of concurrency |
|
|
40
28
|
| **Pub/sub invalidation backplane** | Redis pub/sub channel propagates deletes across all instances in real time |
|
|
29
|
+
| **Tag-based invalidation** | Tag entries on write; `invalidateTag('catalog')` evicts all matching entries from L1, disk, and Redis atomically |
|
|
30
|
+
| **Batch read** | `mget()` collects L1 hits, calls `fetchFn` only for misses, preserves ordering |
|
|
41
31
|
| **OOM guard** | Polls `heapUsed/heapTotal` on a timer; emergency-evicts coldest L1 entries before the process crashes |
|
|
42
32
|
| **Cold-start snapshot** | L1 serialised to disk on `SIGTERM`/`SIGINT`, reloaded on next startup — warm cache, cold process |
|
|
43
|
-
| **AES-256-GCM encryption** | L2 (Redis) values, disk spill files, and snapshots encrypted at rest |
|
|
33
|
+
| **AES-256-GCM encryption** | L2 (Redis) values, disk spill files, and snapshots encrypted at rest; zero-downtime key rotation via `previousEncryptionKey` |
|
|
44
34
|
| **Prometheus metrics** | `cache.metrics()` + `CacheService.toPrometheusText()` — drop into any `/metrics` endpoint |
|
|
45
|
-
| **Distributed counter** | `cache.increment()` backed by Redis `INCR` for distributed rate limiting |
|
|
35
|
+
| **Distributed counter** | `cache.increment()` backed by Redis `INCR` for distributed rate limiting; in-process fallback when Redis is disabled |
|
|
46
36
|
| **Pluggable logger** | Bring your own `pino`, `winston`, etc. |
|
|
37
|
+
| **L2 read-only mode** | `l2WriteMode: 'read-only'` reads from Redis but skips all writes — canary deploys, read replicas |
|
|
38
|
+
| **Eviction callback** | `onEviction(key, reason)` fires on every L1 eviction with a typed reason string |
|
|
47
39
|
|
|
48
40
|
---
|
|
49
41
|
|
|
@@ -94,6 +86,23 @@ const dashboard = await cache.get(
|
|
|
94
86
|
// Distributed rate-limiting counter
|
|
95
87
|
const hits = await cache.increment(`ratelimit:${ip}`, 60 /* TTL seconds */);
|
|
96
88
|
|
|
89
|
+
// Check if a key is cached (fast, no fetch)
|
|
90
|
+
const isCached = cache.has(`user:${userId}`);
|
|
91
|
+
|
|
92
|
+
// Batch read
|
|
93
|
+
const [userA, userB] = await cache.mget(
|
|
94
|
+
[`user:${userIdA}`, `user:${userIdB}`],
|
|
95
|
+
(missKeys) => db.users.findByIds(missKeys).then(rowsToMap),
|
|
96
|
+
300,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Tag entries for group invalidation
|
|
100
|
+
await cache.set(`product:${id}`, product, 300, undefined, { tags: ['catalog'] });
|
|
101
|
+
await cache.invalidateTag('catalog'); // evict all catalog entries
|
|
102
|
+
|
|
103
|
+
// Health check with tier latencies
|
|
104
|
+
const { l1, disk, l2 } = await cache.ping();
|
|
105
|
+
|
|
97
106
|
// Prometheus metrics
|
|
98
107
|
const snap = cache.metrics();
|
|
99
108
|
console.log(CacheService.toPrometheusText(snap));
|
|
@@ -152,6 +161,29 @@ CacheService.create({
|
|
|
152
161
|
// node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
|
|
153
162
|
encryptionKey: process.env.CACHE_ENCRYPTION_KEY,
|
|
154
163
|
|
|
164
|
+
// Zero-downtime key rotation — remove after all old entries have expired
|
|
165
|
+
previousEncryptionKey: process.env.PREV_ENCRYPTION_KEY,
|
|
166
|
+
previousEncryptionMode: 'aes-256-gcm', // defaults to current encryptionMode
|
|
167
|
+
|
|
168
|
+
// ── L2 write mode ────────────────────────────────────────────────────
|
|
169
|
+
// 'read-write' (default) — reads and writes to Redis
|
|
170
|
+
// 'read-only' — reads from Redis, skips all writes (canary / replica)
|
|
171
|
+
l2WriteMode: 'read-write',
|
|
172
|
+
|
|
173
|
+
// ── Stale-if-error ───────────────────────────────────────────────────
|
|
174
|
+
// Extra seconds to extend a stale L1 entry's expiry when a SWR fetchFn fails.
|
|
175
|
+
// Prevents serving errors while the upstream is temporarily down.
|
|
176
|
+
staleIfError: 300, // keep stale for 5 more minutes on revalidation error
|
|
177
|
+
|
|
178
|
+
// ── Eviction callback ────────────────────────────────────────────────
|
|
179
|
+
// Called synchronously whenever L1 evicts a key.
|
|
180
|
+
// reason: 'capacity' | 'category' | 'rebalance' | 'oom' | 'ttl' | 'manual'
|
|
181
|
+
onEviction: (key, reason) => metrics.increment(`cache.eviction.${reason}`),
|
|
182
|
+
|
|
183
|
+
// ── Prometheus instance label ─────────────────────────────────────────
|
|
184
|
+
// Adds an `instance` label to every metric in toPrometheusText().
|
|
185
|
+
instanceName: 'api-us-east-1',
|
|
186
|
+
|
|
155
187
|
// ── Cold-start snapshot ──────────────────────────────────────────────
|
|
156
188
|
snapshotPath: '/tmp/my-app-cache-snapshot.msgpack',
|
|
157
189
|
snapshotMaxAgeMs: 2 * 60 * 60 * 1000, // 2 hours (default)
|
|
@@ -179,6 +211,14 @@ CacheService.create({
|
|
|
179
211
|
|
|
180
212
|
Returns the process-level singleton. Options are only applied on the **first** call per namespace — subsequent calls return the existing instance.
|
|
181
213
|
|
|
214
|
+
### `CacheService.createAsync(optionsOrPromise)` → `Promise<CacheService>`
|
|
215
|
+
|
|
216
|
+
Async factory that resolves a `Promise<CacheOptions>` before constructing the singleton. Useful when config is fetched from a secret store at startup.
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const cache = await CacheService.createAsync(fetchSecretsFromVault());
|
|
220
|
+
```
|
|
221
|
+
|
|
182
222
|
### `CacheService.reset(options?)` → `CacheService`
|
|
183
223
|
|
|
184
224
|
Destroys the existing singleton and creates a fresh one. Useful in tests.
|
|
@@ -187,6 +227,8 @@ Destroys the existing singleton and creates a fresh one. Useful in tests.
|
|
|
187
227
|
|
|
188
228
|
Get from cache or call `fetchFn` on a miss. The inflight map ensures `fetchFn` fires at most once per key regardless of concurrency.
|
|
189
229
|
|
|
230
|
+
> **Reference semantics:** on an L1 hit, the returned value is the live JS object stored in the entry — not a deep copy. Mutating it will corrupt the cached entry. Deep-clone at the call site if you need an independent copy.
|
|
231
|
+
|
|
190
232
|
| Parameter | Type | Default | Description |
|
|
191
233
|
|---|---|---|---|
|
|
192
234
|
| `key` | `string` | — | Cache key |
|
|
@@ -195,29 +237,121 @@ Get from cache or call `fetchFn` on a miss. The inflight map ensures `fetchFn` f
|
|
|
195
237
|
| `opts.swr` | `number` | `0` | Stale-While-Revalidate grace seconds |
|
|
196
238
|
| `opts.priority` | `CachePriority` | auto-inferred | Eviction priority override |
|
|
197
239
|
|
|
198
|
-
### `cache.set<T>(key, data, ttlSeconds?, priority?)` → `Promise<void>`
|
|
240
|
+
### `cache.set<T>(key, data, ttlSeconds?, priority?, opts?)` → `Promise<void>`
|
|
199
241
|
|
|
200
242
|
Writes to L1 and (in production) L2. Publishes an invalidation to the backplane.
|
|
201
243
|
|
|
244
|
+
| Parameter | Type | Default | Description |
|
|
245
|
+
|---|---|---|---|
|
|
246
|
+
| `opts.tags` | `string[]` | `[]` | Associate tags with this entry for group invalidation |
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
await cache.set('product:1', data, 60, undefined, { tags: ['catalog', 'featured'] });
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### `cache.mget<T>(keys, fetchFn, ttlSeconds?, priority?)` → `Promise<(T | undefined)[]>`
|
|
253
|
+
|
|
254
|
+
Batch read. Returns L1-cached values for hot keys; calls `fetchFn` only with the keys that missed. Preserves input ordering.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
const [userA, userB] = await cache.mget(
|
|
258
|
+
['user:1', 'user:2'],
|
|
259
|
+
(missKeys) => db.users.findByIds(missKeys).then(rowsToMap),
|
|
260
|
+
300,
|
|
261
|
+
);
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### `cache.has(key)` → `boolean`
|
|
265
|
+
|
|
266
|
+
Return `true` if the key exists in L1 and has not expired. Bloom-filter fast-path — no fetch, no disk or Redis round-trip.
|
|
267
|
+
|
|
268
|
+
### `cache.ttl(key)` → `number | null`
|
|
269
|
+
|
|
270
|
+
Return the remaining TTL in **seconds** for a key currently held in L1. Returns `null` if the key is absent or expired. Does not fetch or consume the value.
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
const remaining = cache.ttl('user:123'); // e.g. 247 (seconds left)
|
|
274
|
+
if (remaining !== null && remaining < 30) await cache.touch('user:123', 300);
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### `cache.touch(key, newTtlSeconds)` → `Promise<boolean>`
|
|
278
|
+
|
|
279
|
+
Extend the TTL of a key in L1 (and fire-and-forget `EXPIRE` in Redis) without reading or re-fetching its value. Returns `false` if the key is absent or already expired.
|
|
280
|
+
|
|
281
|
+
### `cache.getIfFresh<T>(key)` → `T | null`
|
|
282
|
+
|
|
283
|
+
Return the L1 value only if it is **fresh** (not yet in the SWR grace window). Returns `null` when absent, expired, or stale — without triggering a revalidation.
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
const fresh = cache.getIfFresh<User>('user:123');
|
|
287
|
+
if (fresh !== null) return fresh; // serve from L1, no network hop
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### `cache.invalidateTag(tag)` → `Promise<void>`
|
|
291
|
+
|
|
292
|
+
Evict all entries associated with a tag from L1, disk, and Redis.
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
await cache.set('product:1', data, 60, undefined, { tags: ['catalog'] });
|
|
296
|
+
await cache.set('product:2', data, 60, undefined, { tags: ['catalog'] });
|
|
297
|
+
await cache.invalidateTag('catalog'); // evicts both entries
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### `cache.ping()` → `Promise<CachePingResult>`
|
|
301
|
+
|
|
302
|
+
Measure L1 / disk / Redis latency in milliseconds. Returns `{ l1, disk, l2 }` — `l2` is `null` when Redis is disabled. Suitable for health-check endpoints.
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
app.get('/health', async (_req, res) => {
|
|
306
|
+
const { l1, disk, l2 } = await cache.ping();
|
|
307
|
+
res.json({ status: 'ok', latencyMs: { l1, disk, l2 } });
|
|
308
|
+
});
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### `cache.drainToL2()` → `Promise<number>`
|
|
312
|
+
|
|
313
|
+
Pipeline all live L1 entries to Redis in a single round-trip. Returns the number of keys written. Useful for warming a new Redis node or zero-downtime failover.
|
|
314
|
+
|
|
202
315
|
### `cache.delete(key)` → `Promise<void>`
|
|
203
316
|
|
|
204
317
|
Deletes one exact key or a glob pattern (`user:abc:*`). Propagates to disk, Redis, and all backplane peers.
|
|
205
318
|
|
|
319
|
+
### `cache.clear(prefix?)` → `Promise<void>`
|
|
320
|
+
|
|
321
|
+
Flush all entries, or only those whose key starts with `prefix`. Propagates to disk and Redis.
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
await cache.clear(); // flush everything
|
|
325
|
+
await cache.clear('session:'); // flush only session keys
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### `cache.rebalance()` → `void`
|
|
329
|
+
|
|
330
|
+
Evict L1 entries that now violate the current category or global capacity limits. Useful when `categoryLimits` are tightened after startup — normally, existing entries are not re-evaluated until they expire naturally.
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
// Tighten analytics limit at runtime, then immediately enforce it
|
|
334
|
+
cache.options.categoryLimits['analytics:'].maxEntries = 50;
|
|
335
|
+
cache.rebalance();
|
|
336
|
+
```
|
|
337
|
+
|
|
206
338
|
### `cache.increment(key, ttlSeconds?)` → `Promise<number>`
|
|
207
339
|
|
|
208
|
-
Redis `INCR` — atomically increments a counter, setting TTL on first write.
|
|
340
|
+
Redis `INCR` — atomically increments a counter, setting TTL on first write. When Redis is disabled, maintains an in-process counter with the same TTL semantics so rate-limiting works in dev/test.
|
|
209
341
|
|
|
210
342
|
### `cache.metrics()` → `CacheMetrics`
|
|
211
343
|
|
|
212
344
|
Returns a full metrics snapshot including hit rates, bloom filter stats, backplane counters, OOM eviction history, and tier sizes.
|
|
213
345
|
|
|
214
|
-
### `CacheService.toPrometheusText(metrics, prefix?)` → `string`
|
|
346
|
+
### `CacheService.toPrometheusText(metrics, prefix?, instanceName?)` → `string`
|
|
215
347
|
|
|
216
|
-
Converts a `CacheMetrics` snapshot to Prometheus text exposition format.
|
|
348
|
+
Converts a `CacheMetrics` snapshot to Prometheus text exposition format. Pass `instanceName` to add an `instance` label alongside `namespace`.
|
|
217
349
|
|
|
218
350
|
```typescript
|
|
219
351
|
app.get('/metrics', (_req, res) => {
|
|
220
|
-
res.type('text/plain').send(
|
|
352
|
+
res.type('text/plain').send(
|
|
353
|
+
CacheService.toPrometheusText(cache.metrics(), 'tricache', 'api-us-east-1'),
|
|
354
|
+
);
|
|
221
355
|
});
|
|
222
356
|
```
|
|
223
357
|
|
|
@@ -225,9 +359,17 @@ app.get('/metrics', (_req, res) => {
|
|
|
225
359
|
|
|
226
360
|
Lightweight L1 and disk stats without the full metrics breakdown.
|
|
227
361
|
|
|
228
|
-
### `cache.writeSnapshot()` / `cache.loadSnapshot()`
|
|
362
|
+
### `cache.writeSnapshot(altPath?)` / `cache.loadSnapshot()`
|
|
363
|
+
|
|
364
|
+
Manual snapshot control. Called automatically on `SIGTERM`/`SIGINT` — only needed when you manage shutdown yourself. `writeSnapshot()` accepts an optional path to write to an alternate location without touching the configured default snapshot file.
|
|
229
365
|
|
|
230
|
-
|
|
366
|
+
```typescript
|
|
367
|
+
// Graceful-shutdown hook — write to a dated backup path
|
|
368
|
+
process.on('SIGTERM', async () => {
|
|
369
|
+
await cache.writeSnapshot(`/backups/cache-${Date.now()}.snap`);
|
|
370
|
+
process.exit(0);
|
|
371
|
+
});
|
|
372
|
+
```
|
|
231
373
|
|
|
232
374
|
### `cache.destroy()` → `Promise<void>`
|
|
233
375
|
|
|
@@ -340,6 +482,18 @@ CacheService.create({ encryptionKey: '<base64-key>', encryptionMode: 'xor' });
|
|
|
340
482
|
|
|
341
483
|
Existing plaintext values are read transparently during key rotation.
|
|
342
484
|
|
|
485
|
+
### Zero-downtime key rotation
|
|
486
|
+
|
|
487
|
+
Set `previousEncryptionKey` to your old key while rolling out a new one. The cache tries the current key first; if decryption fails it transparently retries with the previous key. Remove `previousEncryptionKey` once all old entries have expired.
|
|
488
|
+
|
|
489
|
+
```typescript
|
|
490
|
+
CacheService.create({
|
|
491
|
+
encryptionKey: process.env.NEW_ENCRYPTION_KEY, // new AES-256 key
|
|
492
|
+
previousEncryptionKey: process.env.OLD_ENCRYPTION_KEY, // fallback for old entries
|
|
493
|
+
// previousEncryptionMode defaults to current encryptionMode
|
|
494
|
+
});
|
|
495
|
+
```
|
|
496
|
+
|
|
343
497
|
---
|
|
344
498
|
|
|
345
499
|
## ⚡ WASM Bloom filter
|
|
@@ -366,49 +520,49 @@ Measured on a single Node.js thread (no `await` on synchronous paths):
|
|
|
366
520
|
|
|
367
521
|
| Operation | Throughput | Latency | Notes |
|
|
368
522
|
|---|---|---|---|
|
|
369
|
-
| `get` — hot hit (8K entries) |
|
|
370
|
-
| `get` — cold miss |
|
|
371
|
-
| `set` — tiny payload |
|
|
372
|
-
| `set` — small payload (≈ 512 B) |
|
|
373
|
-
| `set` — large payload (≥ 512 B) |
|
|
374
|
-
| `set` — CRITICAL priority |
|
|
375
|
-
| `delete` — exact key |
|
|
523
|
+
| `get` — hot hit (8K entries) | **2.65 M/s** | 377 ns | bloom → Map lookup → return cached value |
|
|
524
|
+
| `get` — cold miss | **6.77 M/s** | 148 ns | bloom gates → early return |
|
|
525
|
+
| `set` — tiny payload | 915 K/s | 1.09 µs | pack() + Map.set + bloom.add |
|
|
526
|
+
| `set` — small payload (≈ 512 B) | 562 K/s | 1.78 µs | pack() same unified path, larger payload |
|
|
527
|
+
| `set` — large payload (≥ 512 B) | 213.6 K/s | 4.68 µs | pack() larger payload |
|
|
528
|
+
| `set` — CRITICAL priority | 489.7 K/s | 2.04 µs | same set path; skipped in eviction sort |
|
|
529
|
+
| `delete` — exact key | **4.40 M/s** | 227 ns | Map.delete |
|
|
376
530
|
| `deletePattern` — glob wildcard | 7.1 K/s | 141 µs | O(n) Map scan |
|
|
377
531
|
|
|
378
532
|
**CacheService (end-to-end)**
|
|
379
533
|
|
|
380
534
|
| Operation | Throughput | Latency | Notes |
|
|
381
535
|
|---|---|---|---|
|
|
382
|
-
| `get` — L1 warm hit |
|
|
383
|
-
| `get` — SWR stale serve |
|
|
384
|
-
| `get` — miss + fetchFn |
|
|
385
|
-
| `set` |
|
|
386
|
-
| `delete` — exact key |
|
|
387
|
-
| `delete` — glob `*` |
|
|
536
|
+
| `get` — L1 warm hit | **2.16 M/s** | 462 ns | inflight check → l1.get → return cached value |
|
|
537
|
+
| `get` — SWR stale serve | **2.04 M/s** | 491 ns | serves stale; revalidates async |
|
|
538
|
+
| `get` — miss + fetchFn | 14.2 K/s | 70 µs | Promise microtask + l1.set |
|
|
539
|
+
| `set` | 32.3 K/s | 30.93 µs | l1.set + disk.save (fire-and-forget) |
|
|
540
|
+
| `delete` — exact key | 6.5 K/s | 154 µs | l1.delete + disk.delete + backplane |
|
|
541
|
+
| `delete` — glob `*` | 781.5 K/s | 1.28 µs | l1.deletePattern O(n) + disk glob |
|
|
388
542
|
|
|
389
543
|
**Encryption** (IV pool, pre-allocated output buffers)
|
|
390
544
|
|
|
391
545
|
| Mode | Payload | Encrypt | Decrypt |
|
|
392
546
|
|---|---|---|---|
|
|
393
|
-
| AES-256-GCM | 64 B |
|
|
394
|
-
| AES-256-GCM | 512 B |
|
|
395
|
-
| AES-256-GCM | 4 KB |
|
|
396
|
-
| AES-128-GCM | 64 B |
|
|
397
|
-
| AES-128-GCM | 512 B |
|
|
398
|
-
| AES-128-GCM | 4 KB |
|
|
399
|
-
| AES-128-CTR | 64 B |
|
|
400
|
-
| AES-128-CTR | 512 B |
|
|
401
|
-
| AES-128-CTR | 4 KB |
|
|
402
|
-
| XOR _(obfuscation only)_ | 64 B | 2.
|
|
403
|
-
| XOR _(obfuscation only)_ | 512 B |
|
|
404
|
-
| XOR _(obfuscation only)_ | 4 KB |
|
|
547
|
+
| AES-256-GCM | 64 B | 114 K/s / 8.75 µs | 133 K/s / 7.52 µs |
|
|
548
|
+
| AES-256-GCM | 512 B | 70.3 K/s / 14.21 µs | 114 K/s / 8.80 µs |
|
|
549
|
+
| AES-256-GCM | 4 KB | 41.7 K/s / 23.99 µs | 43.0 K/s / 23.24 µs |
|
|
550
|
+
| AES-128-GCM | 64 B | 127 K/s / 7.89 µs | 145 K/s / 6.91 µs |
|
|
551
|
+
| AES-128-GCM | 512 B | 90.8 K/s / 11.01 µs | 132 K/s / 7.59 µs |
|
|
552
|
+
| AES-128-GCM | 4 KB | 48.9 K/s / 20.47 µs | 42.9 K/s / 23.32 µs |
|
|
553
|
+
| AES-128-CTR | 64 B | 181 K/s / 5.51 µs | 192 K/s / 5.21 µs |
|
|
554
|
+
| AES-128-CTR | 512 B | 175 K/s / 5.71 µs | 182 K/s / 5.50 µs |
|
|
555
|
+
| AES-128-CTR | 4 KB | 61.8 K/s / 16.18 µs | 54.0 K/s / 18.51 µs |
|
|
556
|
+
| XOR _(obfuscation only)_ | 64 B | 2.37 M/s / 422 ns | 2.11 M/s / 475 ns |
|
|
557
|
+
| XOR _(obfuscation only)_ | 512 B | 598 K/s / 1.67 µs | 513 K/s / 1.95 µs |
|
|
558
|
+
| XOR _(obfuscation only)_ | 4 KB | 82.7 K/s / 12.09 µs | 146 K/s / 6.84 µs |
|
|
405
559
|
|
|
406
560
|
> AES and XOR string-path numbers shown (Redis L2). Buffer path (disk/snapshot) is 5–20% faster — no base64 overhead.
|
|
407
561
|
> AES-128-GCM is 5–50% faster than AES-256-GCM depending on payload (gap widens at mid-range sizes on AES-NI hardware).
|
|
408
562
|
> AES-128-CTR removes the GHASH MAC step: ~50% faster than AES-128-GCM at small payloads; use only when integrity is guaranteed by transport.
|
|
409
563
|
> XOR numbers are for the buffer path (32-bit word-level XOR, 4 bytes/iteration). XOR dominates at small payloads (no cipher setup) and remains ~2× faster than AES at 4 KB.
|
|
410
564
|
|
|
411
|
-
|
|
565
|
+
See [BENCHMARKS.md](BENCHMARKS.md) for the full breakdown: bloom filter cost, serialization by payload size, eviction pressure, concurrency analysis, multi-tenancy isolation, and a realistic 80/15/5 read/miss/write workload.
|
|
412
566
|
|
|
413
567
|
---
|
|
414
568
|
|
|
@@ -427,7 +581,7 @@ Bug reports and pull requests are welcome!
|
|
|
427
581
|
|
|
428
582
|
## 🛡️ Security
|
|
429
583
|
|
|
430
|
-
Found a vulnerability? **Please don't open a public issue.** Report it privately via [GitHub Security Advisories](https://github.com/Kareem411/
|
|
584
|
+
Found a vulnerability? **Please don't open a public issue.** Report it privately via [GitHub Security Advisories](https://github.com/Kareem411/TriCache/security/advisories/new) so it can be patched before disclosure.
|
|
431
585
|
|
|
432
586
|
For encryption key generation and rotation best practices, see the [Encryption](#-encryption) section.
|
|
433
587
|
|