tricache 1.0.1 → 2.0.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 +89 -93
- package/dashboards/tricache-alerts.yaml +80 -4
- package/dashboards/tricache-grafana.json +54 -1
- package/dashboards/tricache-inventory.rules.yml +21 -0
- package/dist/cache-service-BV5T8-20.d.cts +1064 -0
- package/dist/cache-service-UZXOQGEY.js +14 -0
- package/dist/{cache-service-CREOp7MM.d.ts → cache-service-tpyrXvlH.d.ts} +157 -24
- package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
- package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
- package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
- package/dist/{chunk-2AJKEQMZ.js → chunk-KV7KISK2.js} +54 -5
- package/dist/{chunk-JYQFQJNJ.js → chunk-MB3DMVWN.js} +3424 -1022
- package/dist/chunk-RBJRTGFK.js +94 -0
- package/dist/chunk-S5N65I45.js +17 -0
- package/dist/cli.cjs +3694 -1070
- package/dist/cli.d.cts +12 -0
- package/dist/cli.js +210 -14
- package/dist/dashboard/index.cjs +111 -29
- package/dist/dashboard/index.d.cts +185 -0
- package/dist/dashboard/index.d.ts +5 -3
- package/dist/dashboard/index.js +1 -1
- package/dist/drizzle/index.cjs +3578 -1068
- package/dist/drizzle/index.d.cts +46 -0
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +6 -2
- package/dist/edge/index.cjs +368 -162
- package/dist/edge/index.d.cts +134 -0
- package/dist/edge/index.d.ts +11 -4
- package/dist/edge/index.js +314 -155
- package/dist/hono/index.cjs +3614 -1087
- package/dist/hono/index.d.cts +93 -0
- package/dist/hono/index.d.ts +7 -5
- package/dist/hono/index.js +16 -9
- package/dist/hono-CMv2VdQ6.d.cts +404 -0
- package/dist/{hono-DSV2ve66.d.ts → hono-Dvq04kX9.d.ts} +33 -7
- package/dist/http/index.cjs +3712 -1124
- package/dist/http/index.d.cts +103 -0
- package/dist/http/index.d.ts +13 -5
- package/dist/http/index.js +92 -43
- package/dist/index.cjs +4067 -1252
- package/dist/index.d.cts +1071 -0
- package/dist/index.d.ts +123 -27
- package/dist/index.js +878 -21
- package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.cts} +1 -0
- package/dist/murmur3-DF8BFRnu.d.ts +99 -0
- package/dist/nestjs/index.cjs +3635 -1112
- package/dist/nestjs/index.d.cts +299 -0
- package/dist/nestjs/index.d.ts +120 -33
- package/dist/nestjs/index.js +132 -43
- package/dist/next/index.cjs +3704 -1175
- package/dist/next/index.d.cts +238 -0
- package/dist/next/index.d.ts +39 -11
- package/dist/next/index.js +202 -102
- package/dist/prisma/index.cjs +29 -18
- package/dist/prisma/index.d.cts +62 -0
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +17 -18
- package/dist/serialize-worker.cjs +162 -39
- package/dist/serialize-worker.d.cts +2 -0
- package/dist/serialize-worker.js +9 -7
- package/dist/{types-Dyip5wAl.d.ts → types-F8vRWMrE.d.cts} +186 -54
- package/dist/types-F8vRWMrE.d.ts +1636 -0
- package/dist/{utils-CEsU_Z0s.d.ts → utils-Bvzn-rKS.d.cts} +3 -1
- package/dist/utils-Bvzn-rKS.d.ts +29 -0
- package/package.json +116 -37
- package/src/adapters/auto-pipeliner.ts +150 -26
- package/src/adapters/node-redis.ts +106 -27
- package/src/cache-service.ts +2215 -793
- package/src/cli.ts +25 -14
- package/src/codec.ts +3 -3
- package/src/compression.ts +39 -16
- package/src/cross-region.ts +22 -4
- package/src/dashboard/handler.ts +26 -6
- package/src/dashboard/html.ts +35 -10
- package/src/dashboard/index.ts +35 -13
- package/src/dashboard/types.ts +3 -1
- package/src/disk-tier.ts +448 -102
- package/src/drizzle/index.ts +2 -1
- package/src/edge/adapters/cloudflare-do.ts +25 -10
- package/src/edge/adapters/cloudflare-kv.ts +12 -9
- package/src/edge/adapters/upstash.ts +27 -11
- package/src/edge/cache.ts +200 -110
- package/src/edge/hono.ts +23 -6
- package/src/edge/types.ts +17 -5
- package/src/encryption.ts +50 -18
- package/src/env.d.ts +1 -1
- package/src/errors.ts +12 -0
- package/src/hono/index.ts +19 -9
- package/src/http/express.ts +62 -17
- package/src/http/fastify.ts +35 -21
- package/src/http/utils.ts +60 -20
- package/src/index.ts +6 -0
- package/src/ipc-telemetry.ts +35 -9
- package/src/latency-watchdog.ts +5 -1
- package/src/nestjs/decorators.ts +11 -6
- package/src/nestjs/index.ts +2 -0
- package/src/nestjs/keyv-adapter.ts +68 -0
- package/src/nestjs/tricache.module.ts +15 -12
- package/src/nestjs/tricache.store.ts +69 -26
- package/src/nestjs/types.ts +30 -16
- package/src/next/cache-handler.ts +151 -53
- package/src/next/index.ts +1 -0
- package/src/next/types.ts +25 -0
- package/src/origin-capacity.ts +134 -0
- package/src/prisma/index.ts +17 -24
- package/src/remote-snapshot.ts +37 -27
- package/src/serialize-worker.ts +8 -5
- package/src/sigv4-snapshot-adapter.ts +37 -27
- package/src/smart-memory-cache.ts +121 -44
- package/src/types.ts +117 -37
- package/src/utils/cgroup.ts +12 -0
- package/src/utils/config-comparison.ts +29 -0
- package/src/utils/deadline.ts +14 -0
- package/src/utils/diagnostics.ts +27 -0
- package/src/utils/lz4-size.ts +74 -0
- package/src/utils/namespace-key.ts +48 -0
- package/src/utils/query-key.ts +13 -0
- package/src/utils/redis-slot.ts +13 -0
- package/src/utils/snapshot-transfer.ts +83 -0
- package/src/utils/work-limits.ts +73 -0
- package/src/utils/write-revision.ts +4 -0
- package/src/wasm/bloom-filter-wasm.ts +25 -5
- package/src/worker-pool.ts +44 -15
- package/src/wtiny-lfu.ts +82 -20
- package/dist/cache-service-MG7PN6MX.js +0 -12
- package/dist/chunk-3I5L7K6I.js +0 -704
- package/dist/chunk-BQRURGGD.js +0 -60
package/dist/nestjs/index.js
CHANGED
|
@@ -1,75 +1,74 @@
|
|
|
1
|
-
import "../chunk-3I5L7K6I.js";
|
|
2
1
|
import {
|
|
3
|
-
CacheService
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-2AJKEQMZ.js";
|
|
2
|
+
CacheService,
|
|
3
|
+
INDEFINITE_TTL_SECONDS
|
|
4
|
+
} from "../chunk-MB3DMVWN.js";
|
|
5
|
+
import "../chunk-EJXG7WO6.js";
|
|
6
|
+
import "../chunk-KV7KISK2.js";
|
|
9
7
|
|
|
10
8
|
// src/nestjs/tricache.store.ts
|
|
11
|
-
|
|
9
|
+
import { EventEmitter } from "events";
|
|
10
|
+
var TriCacheStore = class extends EventEmitter {
|
|
12
11
|
constructor(cache) {
|
|
12
|
+
super();
|
|
13
13
|
this.cache = cache;
|
|
14
14
|
}
|
|
15
15
|
cache;
|
|
16
|
-
|
|
17
|
-
* Retrieve an item from the cache.
|
|
18
|
-
* Returns undefined on miss (matching cache-manager v5/v6 contract).
|
|
19
|
-
*/
|
|
20
|
-
async get(key) {
|
|
16
|
+
async get(key, options) {
|
|
21
17
|
const val = await this.cache.peek(key);
|
|
22
|
-
|
|
18
|
+
if (val === null) return void 0;
|
|
19
|
+
if (options?.raw) {
|
|
20
|
+
const remaining = this.cache.ttl(key);
|
|
21
|
+
return { value: val, expires: remaining === null ? void 0 : Date.now() + remaining * 1e3 };
|
|
22
|
+
}
|
|
23
|
+
return val;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Set an item in the cache.
|
|
26
27
|
* @param key - Cache key
|
|
27
28
|
* @param value - Cache value
|
|
28
|
-
* @param ttl - TTL in milliseconds
|
|
29
|
+
* @param ttl - TTL in milliseconds. Omitted uses the engine default (300 s);
|
|
30
|
+
* `0` means indefinite; positive values are converted to seconds.
|
|
29
31
|
*/
|
|
30
32
|
async set(key, value, ttl) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
await this.cache.set(key, value, this._ttlSeconds(ttl) ?? 300);
|
|
34
|
+
return value;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* Remove an item from the cache.
|
|
36
38
|
*/
|
|
37
39
|
async del(key) {
|
|
38
40
|
await this.cache.delete(key);
|
|
41
|
+
return true;
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
44
|
* Clear the entire cache namespace.
|
|
42
45
|
*/
|
|
43
46
|
async reset() {
|
|
44
47
|
await this.cache.clear();
|
|
48
|
+
return true;
|
|
45
49
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*/
|
|
49
|
-
async mget(...keys) {
|
|
50
|
+
async mget(keysOrFirst = [], ...rest) {
|
|
51
|
+
const keys = Array.isArray(keysOrFirst) ? keysOrFirst : [keysOrFirst, ...rest];
|
|
50
52
|
if (keys.length === 0) return [];
|
|
51
|
-
return this.cache.mget(keys
|
|
53
|
+
return this.cache.mget(keys);
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
54
56
|
* Batch set multiple entries with per-entry millisecond TTL.
|
|
55
57
|
*/
|
|
56
58
|
async mset(entries) {
|
|
57
|
-
if (entries.length === 0) return;
|
|
59
|
+
if (entries.length === 0) return [];
|
|
58
60
|
const batch = {};
|
|
59
61
|
for (const e of entries) {
|
|
60
|
-
batch[e.key] = {
|
|
61
|
-
value: e.value,
|
|
62
|
-
ttl: typeof e.ttl === "number" && e.ttl > 0 ? Math.round(e.ttl / 1e3) : e.ttl === 0 ? 0 : void 0
|
|
63
|
-
};
|
|
62
|
+
batch[e.key] = { value: e.value, ttl: this._ttlSeconds(e.ttl) ?? 300 };
|
|
64
63
|
}
|
|
65
64
|
await this.cache.mset(batch);
|
|
65
|
+
return entries;
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
async mdel(...keys) {
|
|
71
|
-
if (keys.length === 0) return;
|
|
67
|
+
async mdel(keysOrFirst = [], ...rest) {
|
|
68
|
+
const keys = Array.isArray(keysOrFirst) ? keysOrFirst : [keysOrFirst, ...rest];
|
|
69
|
+
if (keys.length === 0) return true;
|
|
72
70
|
await this.cache.mdel(keys);
|
|
71
|
+
return true;
|
|
73
72
|
}
|
|
74
73
|
/**
|
|
75
74
|
* Scan keys currently resident in the cache.
|
|
@@ -88,6 +87,37 @@ var TriCacheStore = class {
|
|
|
88
87
|
const rem = this.cache.ttl(key);
|
|
89
88
|
return rem !== null ? rem * 1e3 : void 0;
|
|
90
89
|
}
|
|
90
|
+
async wrap(key, fetch, ttl, refreshThreshold) {
|
|
91
|
+
const seconds = this._ttlSeconds(ttl);
|
|
92
|
+
const refreshAhead = ttl && refreshThreshold ? Math.max(0, Math.min(1, (ttl - refreshThreshold) / ttl)) : void 0;
|
|
93
|
+
return this.cache.wrap(key, async () => await fetch(), { ttl: seconds, refreshAhead });
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Translate a cache-manager millisecond TTL into engine seconds using the same
|
|
97
|
+
* contract as `set()`: omitted keeps the engine default, `0` means indefinite,
|
|
98
|
+
* and positive values convert exactly (sub-second values round up).
|
|
99
|
+
*/
|
|
100
|
+
_ttlSeconds(ttl) {
|
|
101
|
+
if (ttl === void 0) return void 0;
|
|
102
|
+
if (typeof ttl !== "number" || !Number.isFinite(ttl) || ttl < 0) {
|
|
103
|
+
throw new TypeError("TriCacheStore TTL must be a finite non-negative number of milliseconds");
|
|
104
|
+
}
|
|
105
|
+
if (ttl === 0) return INDEFINITE_TTL_SECONDS;
|
|
106
|
+
return Math.max(1e-3, ttl / 1e3);
|
|
107
|
+
}
|
|
108
|
+
cacheId() {
|
|
109
|
+
return `tricache:${this.cache.options.namespace ?? "default"}`;
|
|
110
|
+
}
|
|
111
|
+
get stores() {
|
|
112
|
+
return [this];
|
|
113
|
+
}
|
|
114
|
+
async clear() {
|
|
115
|
+
await this.reset();
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
async disconnect() {
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
91
121
|
};
|
|
92
122
|
|
|
93
123
|
// src/nestjs/types.ts
|
|
@@ -99,17 +129,17 @@ var TriCacheModule = class _TriCacheModule {
|
|
|
99
129
|
/**
|
|
100
130
|
* Register TriCache module synchronously with static configuration options.
|
|
101
131
|
*/
|
|
102
|
-
static register(options = {}) {
|
|
132
|
+
static register(options = {}, moduleOptions = {}) {
|
|
103
133
|
const cache = CacheService.create(options);
|
|
104
|
-
const
|
|
134
|
+
const provideCacheManager = moduleOptions.provideCacheManager ?? true;
|
|
105
135
|
return {
|
|
106
136
|
module: _TriCacheModule,
|
|
107
137
|
global: true,
|
|
108
138
|
providers: [
|
|
109
139
|
{ provide: TRICACHE_SERVICE, useValue: cache },
|
|
110
|
-
{ provide: CACHE_MANAGER, useValue:
|
|
140
|
+
...provideCacheManager ? [{ provide: CACHE_MANAGER, useValue: new TriCacheStore(cache) }] : []
|
|
111
141
|
],
|
|
112
|
-
exports: [TRICACHE_SERVICE, CACHE_MANAGER]
|
|
142
|
+
exports: [TRICACHE_SERVICE, ...provideCacheManager ? [CACHE_MANAGER] : []]
|
|
113
143
|
};
|
|
114
144
|
}
|
|
115
145
|
/**
|
|
@@ -117,20 +147,21 @@ var TriCacheModule = class _TriCacheModule {
|
|
|
117
147
|
*/
|
|
118
148
|
static registerAsync(asyncOptions) {
|
|
119
149
|
const asyncProviders = this.createAsyncProviders(asyncOptions);
|
|
150
|
+
const provideCacheManager = asyncOptions.provideCacheManager ?? true;
|
|
120
151
|
return {
|
|
121
152
|
module: _TriCacheModule,
|
|
122
153
|
global: true,
|
|
123
154
|
imports: asyncOptions.imports || [],
|
|
124
155
|
providers: [
|
|
125
156
|
...asyncProviders,
|
|
126
|
-
{
|
|
157
|
+
...provideCacheManager ? [{
|
|
127
158
|
provide: CACHE_MANAGER,
|
|
128
159
|
useFactory: (cache) => new TriCacheStore(cache),
|
|
129
160
|
inject: [TRICACHE_SERVICE]
|
|
130
|
-
},
|
|
161
|
+
}] : [],
|
|
131
162
|
...asyncOptions.extraProviders || []
|
|
132
163
|
],
|
|
133
|
-
exports: [TRICACHE_SERVICE, CACHE_MANAGER]
|
|
164
|
+
exports: [TRICACHE_SERVICE, ...provideCacheManager ? [CACHE_MANAGER] : []]
|
|
134
165
|
};
|
|
135
166
|
}
|
|
136
167
|
static createAsyncProviders(options) {
|
|
@@ -171,6 +202,65 @@ var TriCacheModule = class _TriCacheModule {
|
|
|
171
202
|
}
|
|
172
203
|
};
|
|
173
204
|
|
|
205
|
+
// src/nestjs/keyv-adapter.ts
|
|
206
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
207
|
+
var TriCacheKeyvAdapter = class extends EventEmitter2 {
|
|
208
|
+
constructor(cache) {
|
|
209
|
+
super();
|
|
210
|
+
this.cache = cache;
|
|
211
|
+
}
|
|
212
|
+
cache;
|
|
213
|
+
_namespace;
|
|
214
|
+
get namespace() {
|
|
215
|
+
return this._namespace;
|
|
216
|
+
}
|
|
217
|
+
set namespace(value) {
|
|
218
|
+
if (value && ["*", "?", "[", "]", "\\"].some((character) => value.includes(character))) {
|
|
219
|
+
throw new Error("Keyv namespace must not contain glob characters");
|
|
220
|
+
}
|
|
221
|
+
this._namespace = value;
|
|
222
|
+
}
|
|
223
|
+
async get(key) {
|
|
224
|
+
const value = await this.cache.peek(key);
|
|
225
|
+
return value === null ? void 0 : value;
|
|
226
|
+
}
|
|
227
|
+
async set(key, value, ttl) {
|
|
228
|
+
if (ttl !== void 0 && (!Number.isFinite(ttl) || ttl < 0)) throw new Error("Keyv TTL must be finite and non-negative");
|
|
229
|
+
const ttlSeconds = ttl === void 0 ? 0 : ttl / 1e3;
|
|
230
|
+
await this.cache.set(key, value, ttlSeconds);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
async delete(key) {
|
|
234
|
+
const found = await this.has(key);
|
|
235
|
+
await this.cache.delete(key);
|
|
236
|
+
return found;
|
|
237
|
+
}
|
|
238
|
+
async clear() {
|
|
239
|
+
await this.cache.clear(this._namespace ? `${this._namespace}:` : void 0);
|
|
240
|
+
}
|
|
241
|
+
async has(key) {
|
|
242
|
+
return await this.cache.peek(key) !== null;
|
|
243
|
+
}
|
|
244
|
+
async getMany(keys) {
|
|
245
|
+
return this.cache.mget(keys);
|
|
246
|
+
}
|
|
247
|
+
async deleteMany(keys) {
|
|
248
|
+
const found = await this.cache.mget(keys);
|
|
249
|
+
await this.cache.mdel(keys);
|
|
250
|
+
return found.every((value) => value !== void 0 && value !== null);
|
|
251
|
+
}
|
|
252
|
+
async setMany(entries) {
|
|
253
|
+
const results = await Promise.all(entries.map((entry) => this.set(entry.key, entry.value, entry.ttl)));
|
|
254
|
+
return results;
|
|
255
|
+
}
|
|
256
|
+
async hasMany(keys) {
|
|
257
|
+
const values = await this.cache.mget(keys);
|
|
258
|
+
return values.map((value) => value !== null && value !== void 0);
|
|
259
|
+
}
|
|
260
|
+
async disconnect() {
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
174
264
|
// src/nestjs/decorators.ts
|
|
175
265
|
function resolveCacheInstance(ctx) {
|
|
176
266
|
return ctx?.cacheService || ctx?.cache || ctx?.cacheStore?.cache || CacheService.create();
|
|
@@ -188,10 +278,8 @@ function Cacheable(options = {}) {
|
|
|
188
278
|
const key = typeof options.key === "function" ? options.key(...args) : typeof options.key === "string" ? options.key : `${className}:${methodName}:${JSON.stringify(args)}`;
|
|
189
279
|
let ttlSeconds = options.ttl ?? 300;
|
|
190
280
|
const rawTtl = options.ttl;
|
|
191
|
-
if (typeof rawTtl === "number") {
|
|
192
|
-
|
|
193
|
-
ttlSeconds = Math.round(rawTtl / 1e3);
|
|
194
|
-
}
|
|
281
|
+
if (typeof rawTtl === "number" && options.ttlUnit === "milliseconds") {
|
|
282
|
+
ttlSeconds = rawTtl / 1e3;
|
|
195
283
|
}
|
|
196
284
|
const tags = typeof options.tags === "function" ? options.tags(...args) : options.tags;
|
|
197
285
|
const dependsOn = typeof options.dependsOn === "function" ? options.dependsOn(...args) : options.dependsOn;
|
|
@@ -247,6 +335,7 @@ export {
|
|
|
247
335
|
CacheEvict,
|
|
248
336
|
Cacheable,
|
|
249
337
|
TRICACHE_SERVICE,
|
|
338
|
+
TriCacheKeyvAdapter,
|
|
250
339
|
TriCacheModule,
|
|
251
340
|
TriCacheStore,
|
|
252
341
|
nestjs_default as default
|