tricache 0.7.0 → 0.8.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/LICENSE +21 -21
- package/README.md +144 -1428
- package/bin/tricache.js +8 -8
- package/dashboards/tricache-alerts.yaml +54 -0
- package/dashboards/tricache-grafana.json +548 -0
- package/dist/cache-service-5MZXFIGK.js +12 -0
- package/dist/cache-service-CyLdpo77.d.ts +871 -0
- package/dist/{chunk-3XQUQBOZ.js → chunk-6PQ5MOWR.js} +2950 -523
- package/dist/chunk-7RV5ZVBB.js +1023 -0
- package/dist/{chunk-PFB5FMEY.js → chunk-LJ5QJB5O.js} +116 -20
- package/dist/chunk-QNU7B43J.js +687 -0
- package/dist/chunk-UGD4VEPD.js +138 -0
- package/dist/chunk-XZL45ABR.js +108 -0
- package/dist/chunk-ZTSWCFYO.js +135 -0
- package/dist/cli.cjs +2894 -518
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +103 -5
- package/dist/dashboard/index.cjs +1065 -0
- package/dist/dashboard/index.d.ts +183 -0
- package/dist/dashboard/index.js +22 -0
- package/dist/drizzle/index.cjs +2648 -508
- package/dist/drizzle/index.d.ts +3 -1
- package/dist/drizzle/index.js +1 -1
- package/dist/edge/index.cjs +1498 -0
- package/dist/edge/index.d.ts +127 -0
- package/dist/edge/index.js +1109 -0
- package/dist/hono-DQRS1Xd7.d.ts +370 -0
- package/dist/http/index.cjs +3038 -589
- package/dist/http/index.d.ts +109 -23
- package/dist/http/index.js +238 -62
- package/dist/index.cjs +6962 -2487
- package/dist/index.d.ts +547 -30
- package/dist/index.js +104 -5
- package/dist/murmur3-CMGw9PbV.d.ts +98 -0
- package/dist/nestjs/index.cjs +2586 -498
- package/dist/nestjs/index.d.ts +3 -1
- package/dist/nestjs/index.js +6 -3
- package/dist/next/index.cjs +2633 -519
- package/dist/next/index.d.ts +13 -7
- package/dist/next/index.js +45 -18
- package/dist/prisma/index.cjs +2 -1
- package/dist/prisma/index.d.ts +3 -1
- package/dist/prisma/index.js +2 -1
- package/dist/serialize-worker.cjs +31 -19
- package/dist/serialize-worker.js +1 -1
- package/dist/{cache-service-BblHuF3i.d.ts → types-B6krw64X.d.ts} +605 -646
- package/package.json +37 -7
- package/src/adapters/auto-pipeliner.ts +206 -0
- package/src/adapters/node-redis.ts +370 -0
- package/src/cache-service.ts +4231 -3226
- package/src/cli.ts +261 -143
- package/src/codec.ts +72 -0
- package/src/compression.ts +56 -63
- package/src/cross-region.ts +245 -0
- package/src/dashboard/handler.ts +392 -0
- package/src/dashboard/html.ts +594 -0
- package/src/dashboard/index.ts +195 -0
- package/src/dashboard/types.ts +96 -0
- package/src/disk-tier.ts +1223 -821
- package/src/drizzle/index.ts +86 -86
- package/src/edge/adapters/cloudflare-do.ts +130 -0
- package/src/edge/adapters/cloudflare-kv.ts +115 -0
- package/src/edge/adapters/upstash.ts +143 -0
- package/src/edge/cache.ts +797 -0
- package/src/edge/crypto.ts +182 -0
- package/src/edge/hono.ts +203 -0
- package/src/edge/index.ts +37 -0
- package/src/edge/types.ts +230 -0
- package/src/edge/utils/base64.ts +63 -0
- package/src/edge/utils/murmur3.ts +179 -0
- package/src/encryption.ts +635 -493
- package/src/http/express.ts +195 -0
- package/src/http/fastify.ts +260 -0
- package/src/http/index.ts +46 -223
- package/src/http/utils.ts +92 -0
- package/src/index.ts +149 -47
- package/src/ipc-telemetry.ts +481 -0
- package/src/latency-watchdog.ts +282 -0
- package/src/nestjs/decorators.ts +161 -161
- package/src/nestjs/index.ts +23 -23
- package/src/nestjs/tricache.module.ts +104 -104
- package/src/nestjs/tricache.store.ts +97 -97
- package/src/nestjs/types.ts +79 -79
- package/src/next/cache-handler.ts +271 -244
- package/src/next/index.ts +37 -37
- package/src/next/isr-handler.ts +105 -105
- package/src/next/types.ts +130 -130
- package/src/prisma/index.ts +154 -151
- package/src/remote-snapshot.ts +153 -0
- package/src/serialize-worker.ts +120 -120
- package/src/sigv4-snapshot-adapter.ts +260 -0
- package/src/smart-memory-cache.ts +1109 -1024
- package/src/types.ts +1199 -902
- package/src/utils/cgroup.ts +100 -0
- package/src/utils/tracing.ts +54 -0
- package/src/wasm/bloom-filter-wasm.ts +109 -102
- package/src/worker-pool.ts +299 -299
- package/src/wtiny-lfu.ts +624 -0
- package/dist/cache-service-AJASH5FX.js +0 -7
- package/dist/chunk-UBSR5UYA.js +0 -0
package/src/http/index.ts
CHANGED
|
@@ -1,223 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* tricache/http — Universal HTTP Caching, ETag generation, and 304 Not Modified middleware
|
|
3
|
-
* for Express
|
|
4
|
-
*
|
|
5
|
-
* Usage with Express:
|
|
6
|
-
* import {
|
|
7
|
-
* app.get('/api/users',
|
|
8
|
-
*
|
|
9
|
-
* Usage with
|
|
10
|
-
* import {
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let activeCache = cache;
|
|
48
|
-
if (!activeCache) {
|
|
49
|
-
const { CacheService } = await import('../cache-service.js');
|
|
50
|
-
activeCache = CacheService.create();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const key = keyGenerator ? keyGenerator(req) : `http:${req.method}:${req.originalUrl || req.url}`;
|
|
54
|
-
const ifNoneMatch = req.headers ? req.headers['if-none-match'] : undefined;
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const cached = await activeCache.get<{ body: unknown; contentType?: string; etag?: string }>(
|
|
58
|
-
key,
|
|
59
|
-
async () => {
|
|
60
|
-
return new Promise((resolve) => {
|
|
61
|
-
const origJson = res.json?.bind(res);
|
|
62
|
-
const origSend = res.send?.bind(res);
|
|
63
|
-
|
|
64
|
-
if (origJson) {
|
|
65
|
-
res.json = (body: any) => {
|
|
66
|
-
const bodyEtag = etag ? generateETag(body) : undefined;
|
|
67
|
-
resolve({ body, contentType: 'application/json; charset=utf-8', etag: bodyEtag });
|
|
68
|
-
if (ifNoneMatch && ifNoneMatch === bodyEtag) {
|
|
69
|
-
return res.status(304).end();
|
|
70
|
-
}
|
|
71
|
-
if (bodyEtag && res.setHeader) res.setHeader('ETag', bodyEtag);
|
|
72
|
-
return origJson(body);
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (origSend) {
|
|
77
|
-
res.send = (body: any) => {
|
|
78
|
-
const bodyEtag = etag ? generateETag(body) : undefined;
|
|
79
|
-
resolve({ body, contentType: res.getHeader ? res.getHeader('content-type') : undefined, etag: bodyEtag });
|
|
80
|
-
if (ifNoneMatch && ifNoneMatch === bodyEtag) {
|
|
81
|
-
return res.status(304).end();
|
|
82
|
-
}
|
|
83
|
-
if (bodyEtag && res.setHeader) res.setHeader('ETag', bodyEtag);
|
|
84
|
-
return origSend(body);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
next();
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
ttl,
|
|
92
|
-
{ swr, tags }
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
if (!res.headersSent) {
|
|
96
|
-
if (cached.etag) {
|
|
97
|
-
if (res.setHeader) res.setHeader('ETag', cached.etag);
|
|
98
|
-
if (ifNoneMatch === cached.etag) {
|
|
99
|
-
return res.status(304).end();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (cached.contentType && res.setHeader) {
|
|
103
|
-
res.setHeader('Content-Type', cached.contentType);
|
|
104
|
-
}
|
|
105
|
-
if (typeof cached.body === 'object' && cached.body !== null && res.json) {
|
|
106
|
-
return res.json(cached.body);
|
|
107
|
-
} else if (res.send) {
|
|
108
|
-
return res.send(cached.body);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
} catch (err) {
|
|
112
|
-
next(err);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/** Hono / Web Standard middleware */
|
|
118
|
-
export function honoCache(options: HttpCacheOptions = {}) {
|
|
119
|
-
const { cache, keyGenerator, etag = true, ttl = 300, swr, tags } = options;
|
|
120
|
-
|
|
121
|
-
return async (c: any, next: any) => {
|
|
122
|
-
if (c.req.method !== 'GET' && c.req.method !== 'HEAD') {
|
|
123
|
-
return await next();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
let activeCache = cache;
|
|
127
|
-
if (!activeCache) {
|
|
128
|
-
const { CacheService } = await import('../cache-service.js');
|
|
129
|
-
activeCache = CacheService.create();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const key = keyGenerator ? keyGenerator(c.req) : `http:${c.req.method}:${c.req.url}`;
|
|
133
|
-
const ifNoneMatch = c.req.header ? c.req.header('if-none-match') : undefined;
|
|
134
|
-
|
|
135
|
-
const cached = await activeCache.get<{ body: unknown; contentType?: string; etag?: string }>(
|
|
136
|
-
key,
|
|
137
|
-
async () => {
|
|
138
|
-
await next();
|
|
139
|
-
const res = c.res;
|
|
140
|
-
const text = await res.clone().text();
|
|
141
|
-
const bodyEtag = etag ? generateETag(text) : undefined;
|
|
142
|
-
return {
|
|
143
|
-
body: text,
|
|
144
|
-
contentType: res.headers.get('content-type') ?? 'text/plain',
|
|
145
|
-
etag: bodyEtag,
|
|
146
|
-
};
|
|
147
|
-
},
|
|
148
|
-
ttl,
|
|
149
|
-
{ swr, tags }
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
if (cached.etag && ifNoneMatch === cached.etag) {
|
|
153
|
-
return c.body(null, 304, { ETag: cached.etag });
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const headers: Record<string, string> = {};
|
|
157
|
-
if (cached.etag) headers['ETag'] = cached.etag;
|
|
158
|
-
if (cached.contentType) headers['Content-Type'] = cached.contentType;
|
|
159
|
-
|
|
160
|
-
return c.body(cached.body, 200, headers);
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/** Fastify preHandler hook */
|
|
165
|
-
export function fastifyCache(options: HttpCacheOptions = {}) {
|
|
166
|
-
const { cache, keyGenerator, etag = true, ttl = 300, tags } = options;
|
|
167
|
-
|
|
168
|
-
return async (req: any, reply: any) => {
|
|
169
|
-
if (req.method !== 'GET' && req.method !== 'HEAD') return;
|
|
170
|
-
|
|
171
|
-
let activeCache = cache;
|
|
172
|
-
if (!activeCache) {
|
|
173
|
-
const { CacheService } = await import('../cache-service.js');
|
|
174
|
-
activeCache = CacheService.create();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const key = keyGenerator ? keyGenerator(req) : `http:${req.method}:${req.url}`;
|
|
178
|
-
const ifNoneMatch = req.headers ? req.headers['if-none-match'] : undefined;
|
|
179
|
-
|
|
180
|
-
// Fast-path: Check if already cached in L1 / Disk / Redis
|
|
181
|
-
const cached = await activeCache.get<{ body: unknown; contentType?: string; etag?: string } | null>(
|
|
182
|
-
key,
|
|
183
|
-
async () => null,
|
|
184
|
-
0
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
if (cached) {
|
|
188
|
-
if (cached.etag) {
|
|
189
|
-
if (reply.header) reply.header('ETag', cached.etag);
|
|
190
|
-
if (ifNoneMatch === cached.etag) {
|
|
191
|
-
if (reply.code) reply.code(304);
|
|
192
|
-
else if (reply.status) reply.status(304);
|
|
193
|
-
if (reply.send) return reply.send();
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (cached.contentType && reply.header) {
|
|
198
|
-
reply.header('Content-Type', cached.contentType);
|
|
199
|
-
}
|
|
200
|
-
if (reply.send) return reply.send(cached.body);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Miss path: intercept reply.send on completion
|
|
205
|
-
const origSend = reply.send?.bind(reply);
|
|
206
|
-
if (origSend) {
|
|
207
|
-
reply.send = function (payload: any) {
|
|
208
|
-
if (payload !== undefined && payload !== null) {
|
|
209
|
-
const payloadEtag = etag ? generateETag(payload) : undefined;
|
|
210
|
-
const contentType = (reply.getHeader && reply.getHeader('content-type')) || (typeof payload === 'object' ? 'application/json' : 'text/plain');
|
|
211
|
-
activeCache!.set(key, { body: payload, contentType, etag: payloadEtag }, ttl, undefined, { tags }).catch(() => {});
|
|
212
|
-
if (ifNoneMatch && ifNoneMatch === payloadEtag) {
|
|
213
|
-
if (reply.code) reply.code(304);
|
|
214
|
-
else if (reply.status) reply.status(304);
|
|
215
|
-
return origSend();
|
|
216
|
-
}
|
|
217
|
-
if (payloadEtag && reply.header) reply.header('ETag', payloadEtag);
|
|
218
|
-
}
|
|
219
|
-
return origSend(payload);
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* tricache/http — Universal HTTP Caching, ETag generation, and 304 Not Modified middleware
|
|
3
|
+
* for Express and Fastify.
|
|
4
|
+
*
|
|
5
|
+
* Usage with Express:
|
|
6
|
+
* import { createExpressMiddleware } from 'tricache/http';
|
|
7
|
+
* app.get('/api/users', createExpressMiddleware({ cache, ttl: 300, tags: ['users'] }), handler);
|
|
8
|
+
*
|
|
9
|
+
* Usage with Fastify:
|
|
10
|
+
* import { fastifyCachePlugin } from 'tricache/http';
|
|
11
|
+
* await fastify.register(fastifyCachePlugin, { cache, ttl: 300 });
|
|
12
|
+
*
|
|
13
|
+
* For Edge runtimes (Cloudflare Workers, Vercel Edge, Deno) and Hono, use:
|
|
14
|
+
* import { honoEdgeCache } from 'tricache/edge';
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
buildDeterministicKey,
|
|
19
|
+
shouldSkipCache,
|
|
20
|
+
generateETag,
|
|
21
|
+
type KeyDerivationOptions,
|
|
22
|
+
} from './utils.js';
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
createExpressMiddleware,
|
|
26
|
+
expressCache,
|
|
27
|
+
type ExpressCacheOptions,
|
|
28
|
+
type ExpressCacheOptions as HttpCacheOptions,
|
|
29
|
+
type CachedHttpResponse,
|
|
30
|
+
} from './express.js';
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
createFastifyPlugin,
|
|
34
|
+
fastifyCachePlugin,
|
|
35
|
+
fastifyCache,
|
|
36
|
+
type FastifyCacheOptions,
|
|
37
|
+
type CachedFastifyResponse,
|
|
38
|
+
} from './fastify.js';
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
honoEdgeCache as honoCache,
|
|
42
|
+
computeEdgeETag,
|
|
43
|
+
buildEdgeDeterministicKey,
|
|
44
|
+
type HonoEdgeCacheOptions,
|
|
45
|
+
type CachedEdgeHttpResponse,
|
|
46
|
+
} from '../edge/hono.js';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
export interface KeyDerivationOptions {
|
|
4
|
+
/** Custom key derivation function. Overrides default URL and query string serialization. */
|
|
5
|
+
keyGenerator?: (req: any) => string;
|
|
6
|
+
/** Optional list of header names (case-insensitive) to include in the cache key. */
|
|
7
|
+
headerWhitelist?: string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generates a deterministic HTTP cache key from request method, URL path, sorted query parameters,
|
|
12
|
+
* and optional whitelisted headers.
|
|
13
|
+
*
|
|
14
|
+
* Example:
|
|
15
|
+
* GET /api/products?sort=desc&page=2
|
|
16
|
+
* GET /api/products?page=2&sort=desc
|
|
17
|
+
* Both map to: http:GET:/api/products?page=2&sort=desc
|
|
18
|
+
*/
|
|
19
|
+
export function buildDeterministicKey(req: any, options?: KeyDerivationOptions): string {
|
|
20
|
+
if (options?.keyGenerator) {
|
|
21
|
+
return options.keyGenerator(req);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const method = (req.method || 'GET').toUpperCase();
|
|
25
|
+
const rawUrl = req.originalUrl || req.url || '/';
|
|
26
|
+
|
|
27
|
+
const qIdx = rawUrl.indexOf('?');
|
|
28
|
+
const path = qIdx >= 0 ? rawUrl.slice(0, qIdx) : rawUrl;
|
|
29
|
+
let queryString = '';
|
|
30
|
+
|
|
31
|
+
if (qIdx >= 0) {
|
|
32
|
+
const rawQuery = rawUrl.slice(qIdx + 1);
|
|
33
|
+
try {
|
|
34
|
+
const params = new URLSearchParams(rawQuery);
|
|
35
|
+
params.sort();
|
|
36
|
+
queryString = params.toString();
|
|
37
|
+
} catch {
|
|
38
|
+
queryString = rawQuery;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let key = `http:${method}:${path}`;
|
|
43
|
+
if (queryString) {
|
|
44
|
+
key += `?${queryString}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (options?.headerWhitelist && options.headerWhitelist.length > 0 && req.headers) {
|
|
48
|
+
const sortedHeaders = [...options.headerWhitelist].sort();
|
|
49
|
+
for (const h of sortedHeaders) {
|
|
50
|
+
const normalizedHeader = h.toLowerCase();
|
|
51
|
+
const val = req.headers[normalizedHeader];
|
|
52
|
+
if (val !== undefined && val !== null && val !== '') {
|
|
53
|
+
const headerStr = Array.isArray(val) ? val.join(',') : String(val);
|
|
54
|
+
key += `|h:${normalizedHeader}=${headerStr}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return key;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Checks if request specifies Cache-Control bypass directives (no-cache, no-store)
|
|
64
|
+
* or matches a custom skipCache predicate.
|
|
65
|
+
*/
|
|
66
|
+
export function shouldSkipCache(req: any, customSkip?: (req: any) => boolean): boolean {
|
|
67
|
+
if (customSkip && customSkip(req)) return true;
|
|
68
|
+
|
|
69
|
+
const cc = req.headers ? (req.headers['cache-control'] || req.headers['Cache-Control']) : undefined;
|
|
70
|
+
if (typeof cc === 'string') {
|
|
71
|
+
const lower = cc.toLowerCase();
|
|
72
|
+
if (lower.includes('no-cache') || lower.includes('no-store')) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Compute a weak ETag (W/"...") from string, Buffer, or JSON-serializable object.
|
|
82
|
+
*/
|
|
83
|
+
export function generateETag(data: unknown): string {
|
|
84
|
+
const str = typeof data === 'string'
|
|
85
|
+
? data
|
|
86
|
+
: Buffer.isBuffer(data)
|
|
87
|
+
? data.toString('utf8')
|
|
88
|
+
: JSON.stringify(data);
|
|
89
|
+
|
|
90
|
+
const hash = crypto.createHash('sha1').update(str).digest('hex').slice(0, 16);
|
|
91
|
+
return `W/"${str.length.toString(16)}-${hash}"`;
|
|
92
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,47 +1,149 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* tricache — three-tier cache for Node.js
|
|
3
|
-
*
|
|
4
|
-
* L1 (RAM) → L1.5 (disk) → L2 (Redis/Valkey) → your fetch function
|
|
5
|
-
*
|
|
6
|
-
* Quick start:
|
|
7
|
-
* import { CacheService, CachePriority } from 'tricache';
|
|
8
|
-
*
|
|
9
|
-
* const cache = CacheService.create({ redisHost: 'localhost' });
|
|
10
|
-
*
|
|
11
|
-
* const user = await cache.get(
|
|
12
|
-
* `user:${userId}`,
|
|
13
|
-
* () => db.users.findById(userId),
|
|
14
|
-
* 300, // 5-minute TTL
|
|
15
|
-
* );
|
|
16
|
-
*
|
|
17
|
-
* await cache.delete(`user:${userId}`);
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
export { CacheService }
|
|
21
|
-
export {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
type
|
|
33
|
-
type
|
|
34
|
-
type
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
/**
|
|
2
|
+
* tricache — three-tier cache for Node.js
|
|
3
|
+
*
|
|
4
|
+
* L1 (RAM) → L1.5 (disk) → L2 (Redis/Valkey) → your fetch function
|
|
5
|
+
*
|
|
6
|
+
* Quick start:
|
|
7
|
+
* import { CacheService, CachePriority } from 'tricache';
|
|
8
|
+
*
|
|
9
|
+
* const cache = CacheService.create({ redisHost: 'localhost' });
|
|
10
|
+
*
|
|
11
|
+
* const user = await cache.get(
|
|
12
|
+
* `user:${userId}`,
|
|
13
|
+
* () => db.users.findById(userId),
|
|
14
|
+
* 300, // 5-minute TTL
|
|
15
|
+
* );
|
|
16
|
+
*
|
|
17
|
+
* await cache.delete(`user:${userId}`);
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export { CacheService, ProcessTerminationBus, deepMergeOptions } from './cache-service';
|
|
21
|
+
export {
|
|
22
|
+
CacheEncryption,
|
|
23
|
+
EnvelopeEncryption,
|
|
24
|
+
type EncryptionMode,
|
|
25
|
+
type EnvelopeEncryptionOptions,
|
|
26
|
+
} from './encryption';
|
|
27
|
+
export { SmartMemoryCache } from './smart-memory-cache';
|
|
28
|
+
export {
|
|
29
|
+
WTinyLfuCache,
|
|
30
|
+
WTinyLfuPolicy,
|
|
31
|
+
TinyLfuSketch,
|
|
32
|
+
type WTinyLfuOptions,
|
|
33
|
+
type WTinyLfuStats,
|
|
34
|
+
type EvictionResult,
|
|
35
|
+
} from './wtiny-lfu';
|
|
36
|
+
export { DiskTier, resolveDefaultDiskDir } from './disk-tier';
|
|
37
|
+
export { TierLatencyWatchdog, type LatencyWatchdogOptions, type LatencyWatchdogTelemetry } from './latency-watchdog';
|
|
38
|
+
export { WasmBloomFilter } from './wasm/bloom-filter-wasm';
|
|
39
|
+
export { type CompressionAlgorithm } from './compression';
|
|
40
|
+
export { CacheCodec, defaultCodec, type CacheCodecOptions } from './codec';
|
|
41
|
+
export {
|
|
42
|
+
createHttpSnapshotAdapter,
|
|
43
|
+
createCustomSnapshotAdapter,
|
|
44
|
+
createMemorySnapshotAdapter,
|
|
45
|
+
createSigV4SnapshotAdapter,
|
|
46
|
+
createS3SnapshotAdapter,
|
|
47
|
+
createR2SnapshotAdapter,
|
|
48
|
+
SigV4SnapshotAdapter,
|
|
49
|
+
type IRemoteSnapshotAdapter,
|
|
50
|
+
type RemoteSnapshotOptions,
|
|
51
|
+
type HttpSnapshotAdapterOptions,
|
|
52
|
+
type SigV4SnapshotAdapterOptions,
|
|
53
|
+
} from './remote-snapshot';
|
|
54
|
+
export {
|
|
55
|
+
createHttpMeshRelay,
|
|
56
|
+
createCustomCrossRegionRelay,
|
|
57
|
+
createMemoryCrossRegionRelay,
|
|
58
|
+
createCrossRegionWebhookHandler,
|
|
59
|
+
type CrossRegionInvalidationEvent,
|
|
60
|
+
type ICrossRegionRelay,
|
|
61
|
+
type CrossRegionRelayOptions,
|
|
62
|
+
type HttpMeshRelayOptions,
|
|
63
|
+
type WebhookRequestLike,
|
|
64
|
+
type WebhookResponseLike,
|
|
65
|
+
} from './cross-region';
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
NodeRedisAdapter,
|
|
69
|
+
createNodeRedisAdapter,
|
|
70
|
+
type IRedisDriver,
|
|
71
|
+
type IRedisPipeline,
|
|
72
|
+
} from './adapters/node-redis';
|
|
73
|
+
|
|
74
|
+
export {
|
|
75
|
+
AutoPipeliner,
|
|
76
|
+
type AutoPipelinerOptions,
|
|
77
|
+
} from './adapters/auto-pipeliner';
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
resolveAutonomousL1MaxBytes,
|
|
81
|
+
readCgroupMemoryLimit,
|
|
82
|
+
getV8HeapLimit,
|
|
83
|
+
type AutonomousL1Options,
|
|
84
|
+
DEFAULT_AUTONOMOUS_L1_CEILING_BYTES,
|
|
85
|
+
MIN_AUTONOMOUS_L1_FLOOR_BYTES,
|
|
86
|
+
} from './utils/cgroup';
|
|
87
|
+
|
|
88
|
+
export {
|
|
89
|
+
Murmur3BloomFilter,
|
|
90
|
+
murmur3_32,
|
|
91
|
+
type BloomFilterStats,
|
|
92
|
+
} from './edge/utils/murmur3';
|
|
93
|
+
|
|
94
|
+
export {
|
|
95
|
+
CachePriority,
|
|
96
|
+
consoleLogger,
|
|
97
|
+
type ILogger,
|
|
98
|
+
type CachePresetType,
|
|
99
|
+
type CacheOptions,
|
|
100
|
+
type CacheMetrics,
|
|
101
|
+
type CategoryLimit,
|
|
102
|
+
type SmartCacheEntry,
|
|
103
|
+
type DiskCacheEntry,
|
|
104
|
+
type CacheHit,
|
|
105
|
+
type EvictionReason,
|
|
106
|
+
type CachePingResult,
|
|
107
|
+
type ICacheTracer,
|
|
108
|
+
type ICacheSpan,
|
|
109
|
+
type ICacheSpanLink,
|
|
110
|
+
type WrapOptions,
|
|
111
|
+
type LockOptions,
|
|
112
|
+
type ICacheCounter,
|
|
113
|
+
type ICacheObservableGauge,
|
|
114
|
+
type ICacheBatchObservableCallback,
|
|
115
|
+
type ICacheMeter,
|
|
116
|
+
type CacheHealthStatus,
|
|
117
|
+
} from './types';
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
parseTraceParent,
|
|
121
|
+
formatTraceParent,
|
|
122
|
+
type ParsedTraceParent,
|
|
123
|
+
} from './utils/tracing';
|
|
124
|
+
|
|
125
|
+
export {
|
|
126
|
+
tricacheDashboard,
|
|
127
|
+
createNextDashboardHandlers,
|
|
128
|
+
startDashboardServer,
|
|
129
|
+
handleDashboardRequest,
|
|
130
|
+
type DashboardOptions,
|
|
131
|
+
type StandaloneDashboardOptions,
|
|
132
|
+
type DashboardPeerInstance,
|
|
133
|
+
type DashboardActionEvent,
|
|
134
|
+
} from './dashboard/index';
|
|
135
|
+
|
|
136
|
+
export {
|
|
137
|
+
IpcTelemetryServer,
|
|
138
|
+
IpcTelemetryClient,
|
|
139
|
+
resolveIpcSocketPath,
|
|
140
|
+
findActiveSockets,
|
|
141
|
+
renderTopDashboard,
|
|
142
|
+
renderProgressBar,
|
|
143
|
+
formatBytes,
|
|
144
|
+
formatDuration,
|
|
145
|
+
formatNumber,
|
|
146
|
+
type IpcMetricsPayload,
|
|
147
|
+
type IIpcCacheProvider,
|
|
148
|
+
} from './ipc-telemetry';
|
|
149
|
+
|