@warlock.js/cache 5.51.0 → 5.53.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 +36 -0
- package/cjs/index.cjs +528 -122
- package/cjs/index.cjs.map +1 -1
- package/esm/cache-manager.mjs.map +1 -1
- package/esm/cached/auto-key.d.mts +3 -1
- package/esm/cached/auto-key.d.mts.map +1 -1
- package/esm/cached/auto-key.mjs +9 -4
- 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 +40 -3
- package/esm/drivers/base-cache-driver.d.mts.map +1 -1
- package/esm/drivers/base-cache-driver.mjs +57 -7
- package/esm/drivers/base-cache-driver.mjs.map +1 -1
- package/esm/drivers/clone-value.mjs +17 -0
- package/esm/drivers/clone-value.mjs.map +1 -0
- package/esm/drivers/file-cache-driver.d.mts +40 -2
- package/esm/drivers/file-cache-driver.d.mts.map +1 -1
- package/esm/drivers/file-cache-driver.mjs +142 -18
- package/esm/drivers/file-cache-driver.mjs.map +1 -1
- package/esm/drivers/in-memory-tag-index.d.mts +5 -0
- package/esm/drivers/in-memory-tag-index.d.mts.map +1 -1
- package/esm/drivers/in-memory-tag-index.mjs +17 -0
- package/esm/drivers/in-memory-tag-index.mjs.map +1 -1
- package/esm/drivers/lru-memory-cache-driver.d.mts +18 -1
- package/esm/drivers/lru-memory-cache-driver.d.mts.map +1 -1
- package/esm/drivers/lru-memory-cache-driver.mjs +27 -2
- package/esm/drivers/lru-memory-cache-driver.mjs.map +1 -1
- package/esm/drivers/memory-cache-driver.d.mts +16 -1
- package/esm/drivers/memory-cache-driver.d.mts.map +1 -1
- package/esm/drivers/memory-cache-driver.mjs +34 -5
- 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.mjs.map +1 -1
- package/esm/drivers/null-cache-driver.d.mts.map +1 -1
- package/esm/drivers/null-cache-driver.mjs +22 -12
- package/esm/drivers/null-cache-driver.mjs.map +1 -1
- package/esm/drivers/pg-cache-driver.d.mts +19 -0
- package/esm/drivers/pg-cache-driver.d.mts.map +1 -1
- package/esm/drivers/pg-cache-driver.mjs +52 -26
- package/esm/drivers/pg-cache-driver.mjs.map +1 -1
- package/esm/drivers/redis-cache-driver.d.mts +29 -0
- package/esm/drivers/redis-cache-driver.d.mts.map +1 -1
- package/esm/drivers/redis-cache-driver.mjs +70 -36
- 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.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 +16 -0
- package/esm/tag-sample.mjs.map +1 -0
- package/esm/tagged-cache.d.mts +15 -0
- package/esm/tagged-cache.d.mts.map +1 -1
- package/esm/tagged-cache.mjs +31 -10
- package/esm/tagged-cache.mjs.map +1 -1
- package/esm/tagged-scoped-cache.mjs.map +1 -1
- package/esm/types.d.mts +24 -5
- package/esm/types.d.mts.map +1 -1
- package/esm/types.mjs.map +1 -1
- package/esm/utils.d.mts +20 -1
- package/esm/utils.d.mts.map +1 -1
- package/esm/utils.mjs +42 -3
- package/esm/utils.mjs.map +1 -1
- package/llms-full.txt +9 -6
- package/llms.txt +1 -1
- package/package.json +3 -3
- package/skills/cache-basics/SKILL.md +1 -1
- package/skills/pick-cache-driver/SKILL.md +1 -1
- package/skills/use-cache-namespace/SKILL.md +1 -0
- package/skills/use-cache-tags/SKILL.md +1 -1
- package/skills/use-cache-utils/SKILL.md +4 -2
- package/skills/use-cached-hof/SKILL.md +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/file-cache-driver.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"file-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/file-cache-driver.ts"],"mappings":";;;qBAmCa,wBACH,gBAAgB,iBAAiB,6BAC9B,YAAY,iBAAiB;;;;EAKjC;;;;EAKA,WAAW,SAAS;;;;MAahB;;;;MAeA;;;;;;;;;;;YAoBD,aAAa;;;;;YAcb,iBAAiB;;;;;;;;YAWjB,iBAAiB;;;;;;YASjB,cAAc;;;;;;;;;;;;EAuBX,gBAAgB,oBAAiB;;;;;;;;EA0CjC,IACX,KAAK,UACL,YACA,eAAe,WAAW,kBACzB;;;;;;;;;;YAiEa,eACd,kBACA,MAAM,YACL;IAAU;;;;;;;;;;;;;YA2DG,iBAAiB,kBAAkB,YAAY,gBAAgB;;;;YA8B/D,gBAAgB,oBAAoB;;;;;;;YAkBpC,cACd,mBACC;IAAU,OAAO;IAAuB;;;;;;;;YAiC3B,eAAe,KAAK,UAAU,oBAAoB;;;;;;;;;EA0CrD,UAAU;;;;EASV,SAAS;;;;;;YAWN,SAAS,KAAK,WAAW,QAAQ;;;;EA4BpC,IAAI,KAAK,WAAQ;;;;EA0CjB,OAAO,KAAK,WAAQ;;;;YAOjB,aAAa,oBAAoB;;;;EAmBpC,SAAK;;;;EAkBL,WAAO"}
|
|
@@ -6,6 +6,16 @@ import { atomicWriteJsonAsync, ensureDirectoryAsync, getJsonFileAsync, listDirec
|
|
|
6
6
|
import path from "path";
|
|
7
7
|
|
|
8
8
|
//#region ../../packages/cache/src/drivers/file-cache-driver.ts
|
|
9
|
+
/**
|
|
10
|
+
* How many times an exclusive write (or a compare-and-delete) retries while
|
|
11
|
+
* another caller is removing the same entry.
|
|
12
|
+
*/
|
|
13
|
+
const EXCLUSIVE_ATTEMPTS = 50;
|
|
14
|
+
/**
|
|
15
|
+
* A removal guard older than this belongs to a process that died while
|
|
16
|
+
* holding it (the guarded step takes a few milliseconds).
|
|
17
|
+
*/
|
|
18
|
+
const STALE_GUARD_MS = 1e4;
|
|
9
19
|
var FileCacheDriver = class extends BaseCacheDriver {
|
|
10
20
|
constructor(..._args) {
|
|
11
21
|
super(..._args);
|
|
@@ -152,8 +162,9 @@ var FileCacheDriver = class extends BaseCacheDriver {
|
|
|
152
162
|
/**
|
|
153
163
|
* Create `filePath` only if it does not exist. Writes a temp file, then
|
|
154
164
|
* hard-links it to the target (EEXIST = already present). An existing but
|
|
155
|
-
* expired entry is removed
|
|
156
|
-
* link
|
|
165
|
+
* expired entry is removed under the key's removal guard (see
|
|
166
|
+
* {@link withRemovalGuard}), so of several contenders only one can ever
|
|
167
|
+
* win the retried link.
|
|
157
168
|
*
|
|
158
169
|
* Returns `null` when written, or `{ existing }` on conflict.
|
|
159
170
|
*/
|
|
@@ -161,26 +172,21 @@ var FileCacheDriver = class extends BaseCacheDriver {
|
|
|
161
172
|
const tempPath = `${filePath}.${randomBytes(6).toString("hex")}.tmp`;
|
|
162
173
|
try {
|
|
163
174
|
await fs.promises.writeFile(tempPath, JSON.stringify(data, null, 2));
|
|
164
|
-
for (let attempt = 0; attempt <
|
|
175
|
+
for (let attempt = 0; attempt < EXCLUSIVE_ATTEMPTS; attempt++) {
|
|
165
176
|
try {
|
|
166
177
|
await fs.promises.link(tempPath, filePath);
|
|
167
178
|
return null;
|
|
168
179
|
} catch (error) {
|
|
169
180
|
if (error?.code !== "EEXIST") throw error;
|
|
170
181
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (attempt === 0 && expired) {
|
|
180
|
-
await fs.promises.rm(filePath, { force: true });
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
return { existing: null };
|
|
182
|
+
const current = await this.readEntryFile(filePath);
|
|
183
|
+
if (!current) continue;
|
|
184
|
+
if (!current.entry) return { existing: null };
|
|
185
|
+
if (!isExpiredEntry(current.entry)) return { existing: current.entry.data ?? null };
|
|
186
|
+
if (!await this.withRemovalGuard(filePath, async () => {
|
|
187
|
+
const latest = await this.readEntryFile(filePath);
|
|
188
|
+
if (latest?.entry && latest.inode === current.inode && isExpiredEntry(latest.entry)) await fs.promises.unlink(filePath).catch(ignoreMissing);
|
|
189
|
+
})) await delay(1);
|
|
184
190
|
}
|
|
185
191
|
return { existing: null };
|
|
186
192
|
} finally {
|
|
@@ -188,6 +194,106 @@ var FileCacheDriver = class extends BaseCacheDriver {
|
|
|
188
194
|
}
|
|
189
195
|
}
|
|
190
196
|
/**
|
|
197
|
+
* Run `task` while holding the key's removal guard: a `<file>.guard` file
|
|
198
|
+
* created exclusively. Entry files are only ever created by an exclusive
|
|
199
|
+
* link onto a missing path, so while every removal of a live or expired
|
|
200
|
+
* entry by `writeExclusive` / `deleteIfEquals` happens under this guard, no
|
|
201
|
+
* removal can delete an entry another writer has just created.
|
|
202
|
+
*
|
|
203
|
+
* Returns `false` (without running `task`) when another caller holds the
|
|
204
|
+
* guard. A guard left behind by a crashed process is cleared once it is
|
|
205
|
+
* older than {@link STALE_GUARD_MS}.
|
|
206
|
+
*/
|
|
207
|
+
async withRemovalGuard(filePath, task) {
|
|
208
|
+
const guardPath = `${filePath}.guard`;
|
|
209
|
+
let handle;
|
|
210
|
+
try {
|
|
211
|
+
handle = await fs.promises.open(guardPath, "wx");
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (error?.code === "ENOENT") return true;
|
|
214
|
+
if (error?.code !== "EEXIST") throw error;
|
|
215
|
+
await this.clearStaleGuard(guardPath);
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
await handle.close();
|
|
220
|
+
await task();
|
|
221
|
+
return true;
|
|
222
|
+
} finally {
|
|
223
|
+
await fs.promises.unlink(guardPath).catch(() => void 0);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Remove a removal guard whose holder died (older than {@link STALE_GUARD_MS}).
|
|
228
|
+
*/
|
|
229
|
+
async clearStaleGuard(guardPath) {
|
|
230
|
+
try {
|
|
231
|
+
const { mtimeMs } = await fs.promises.stat(guardPath);
|
|
232
|
+
if (Date.now() - mtimeMs > STALE_GUARD_MS) await fs.promises.unlink(guardPath).catch(ignoreMissing);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (error?.code !== "ENOENT") throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Read an entry file together with its inode, so a later step can tell
|
|
239
|
+
* whether the file at the same path is still the one that was read.
|
|
240
|
+
* `undefined` when the file does not exist; `entry: undefined` when it
|
|
241
|
+
* cannot be parsed.
|
|
242
|
+
*/
|
|
243
|
+
async readEntryFile(filePath) {
|
|
244
|
+
let handle;
|
|
245
|
+
try {
|
|
246
|
+
handle = await fs.promises.open(filePath, "r");
|
|
247
|
+
} catch (error) {
|
|
248
|
+
if (error?.code === "ENOENT") return void 0;
|
|
249
|
+
throw error;
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
const { ino } = await handle.stat();
|
|
253
|
+
const text = await handle.readFile("utf-8");
|
|
254
|
+
try {
|
|
255
|
+
const entry = JSON.parse(text);
|
|
256
|
+
return {
|
|
257
|
+
entry: entry && typeof entry === "object" ? entry : void 0,
|
|
258
|
+
inode: ino
|
|
259
|
+
};
|
|
260
|
+
} catch {
|
|
261
|
+
return {
|
|
262
|
+
entry: void 0,
|
|
263
|
+
inode: ino
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
} finally {
|
|
267
|
+
await handle.close();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* {@inheritdoc}
|
|
272
|
+
*
|
|
273
|
+
* Compare-and-delete under the key's removal guard, so a lock released just
|
|
274
|
+
* as it expired never deletes a successor's lock.
|
|
275
|
+
*/
|
|
276
|
+
async deleteIfEquals(key, expected) {
|
|
277
|
+
const parsedKey = this.parseKey(key);
|
|
278
|
+
const fileDirectory = this.keyDirectory(parsedKey);
|
|
279
|
+
const filePath = path.resolve(fileDirectory, this.fileName);
|
|
280
|
+
let deleted = false;
|
|
281
|
+
for (let attempt = 0; attempt < EXCLUSIVE_ATTEMPTS; attempt++) {
|
|
282
|
+
if (await this.withRemovalGuard(filePath, async () => {
|
|
283
|
+
const current = await this.readEntryFile(filePath);
|
|
284
|
+
if (!current?.entry || isExpiredEntry(current.entry) || current.entry.data !== expected) return;
|
|
285
|
+
await fs.promises.unlink(filePath).catch(ignoreMissing);
|
|
286
|
+
deleted = true;
|
|
287
|
+
})) break;
|
|
288
|
+
await delay(1);
|
|
289
|
+
}
|
|
290
|
+
if (!deleted) return false;
|
|
291
|
+
await fs.promises.rmdir(fileDirectory).catch(() => void 0);
|
|
292
|
+
this.log("removed", parsedKey);
|
|
293
|
+
await this.emit("removed", { key: parsedKey });
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
191
297
|
* {@inheritdoc}
|
|
192
298
|
*
|
|
193
299
|
* File driver does not yet ship with a file-lock primitive, so concurrent
|
|
@@ -239,7 +345,7 @@ var FileCacheDriver = class extends BaseCacheDriver {
|
|
|
239
345
|
await this.emit("miss", { key: parsedKey });
|
|
240
346
|
return null;
|
|
241
347
|
}
|
|
242
|
-
const result = await this.parseCachedData(parsedKey, value);
|
|
348
|
+
const result = await this.parseCachedData(parsedKey, value, false);
|
|
243
349
|
if (result === null) await this.emit("miss", { key: parsedKey });
|
|
244
350
|
else await this.emit("hit", {
|
|
245
351
|
key: parsedKey,
|
|
@@ -251,7 +357,12 @@ var FileCacheDriver = class extends BaseCacheDriver {
|
|
|
251
357
|
* {@inheritdoc}
|
|
252
358
|
*/
|
|
253
359
|
async remove(key) {
|
|
254
|
-
|
|
360
|
+
await this.removeParsed(this.parseKey(key));
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* {@inheritdoc}
|
|
364
|
+
*/
|
|
365
|
+
async removeParsed(parsedKey) {
|
|
255
366
|
this.log("removing", parsedKey);
|
|
256
367
|
const fileDirectory = this.keyDirectory(parsedKey);
|
|
257
368
|
try {
|
|
@@ -280,6 +391,19 @@ var FileCacheDriver = class extends BaseCacheDriver {
|
|
|
280
391
|
await this.emit("connected");
|
|
281
392
|
}
|
|
282
393
|
};
|
|
394
|
+
/**
|
|
395
|
+
* Whether a stored entry is past its deadline. `Infinity` (no expiry) is
|
|
396
|
+
* written to JSON as `null`, so only a real number can be expired.
|
|
397
|
+
*/
|
|
398
|
+
function isExpiredEntry(entry) {
|
|
399
|
+
return typeof entry.expiresAt === "number" && entry.expiresAt <= Date.now();
|
|
400
|
+
}
|
|
401
|
+
function ignoreMissing(error) {
|
|
402
|
+
if (error?.code !== "ENOENT") throw error;
|
|
403
|
+
}
|
|
404
|
+
function delay(ms) {
|
|
405
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
406
|
+
}
|
|
283
407
|
|
|
284
408
|
//#endregion
|
|
285
409
|
export { FileCacheDriver };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/file-cache-driver.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport {\n atomicWriteJsonAsync,\n ensureDirectoryAsync,\n getJsonFileAsync,\n listDirectoriesAsync,\n removeDirectoryAsync,\n} from \"@warlock.js/fs\";\nimport path from \"path\";\nimport type {\n CacheData,\n CacheDriver,\n CacheKey,\n CacheSetOptions,\n CacheSetResult,\n CacheTtl,\n FileCacheOptions,\n} from \"../types\";\nimport { CacheConfigurationError, CacheError, CacheUnsupportedError } from \"../types\";\nimport { BaseCacheDriver } from \"./base-cache-driver\";\n\nexport class FileCacheDriver\n extends BaseCacheDriver<FileCacheDriver, FileCacheOptions>\n implements CacheDriver<FileCacheDriver, FileCacheOptions>\n{\n /**\n * {@inheritdoc}\n */\n public name = \"file\";\n\n /**\n * {@inheritdoc}\n */\n public setOptions(options: FileCacheOptions) {\n if (!options.directory) {\n throw new CacheConfigurationError(\n \"File driver requires 'directory' option to be configured.\",\n );\n }\n\n return super.setOptions(options);\n }\n\n /**\n * Get the cache directory\n */\n public get directory() {\n const directory = this.options.directory;\n\n if (typeof directory === \"function\") {\n return directory();\n }\n\n throw new CacheConfigurationError(\n \"Cache directory is not defined, please define it in the file driver options\",\n );\n }\n\n /**\n * Get file name\n */\n public get fileName() {\n const fileName = this.options.fileName;\n\n if (typeof fileName === \"function\") {\n return fileName();\n }\n\n return \"cache.json\";\n }\n\n /**\n * Map a parsed cache key (or namespace) to its on-disk directory.\n *\n * The key must become exactly one directory component: `%` and the path\n * separators are percent-encoded so a hostile key (`../../etc`,\n * `..\\\\..\\\\evil`) turns into an inert directory name instead of a path\n * traversal, while distinct keys can never collide after encoding. Dots are\n * left untouched — the `.`-delimited namespace scheme is purely logical and\n * only ever produces a single filesystem component here.\n */\n protected keyDirectory(parsedKey: string): string {\n // An empty key would resolve to the cache root — `remove(\"{}\")` must never\n // be able to wipe it.\n if (parsedKey === \"\") {\n throw new CacheConfigurationError(\"Cache key must not be empty.\");\n }\n\n return this.containedPath(this.encodeKeySegment(parsedKey));\n }\n\n /**\n * Percent-encode a parsed key into an inert, single-component directory\n * name. Dots are left untouched — see {@link keyDirectory}.\n */\n protected encodeKeySegment(parsedKey: string): string {\n return parsedKey.replace(/%/g, \"%25\").replace(/\\//g, \"%2F\").replace(/\\\\/g, \"%5C\");\n }\n\n /**\n * Reverse of {@link encodeKeySegment} — recovers the logical, dot-delimited\n * parsed key from an on-disk directory name. Used by {@link removeNamespace}\n * to test which sibling directories logically belong to a namespace, since\n * dotted keys (`ns.a`) are stored as sibling directories rather than nested\n * ones (see {@link keyDirectory}'s doc comment).\n */\n protected decodeKeySegment(encoded: string): string {\n return encoded.replace(/%2F/g, \"/\").replace(/%5C/g, \"\\\\\").replace(/%25/g, \"%\");\n }\n\n /**\n * Resolve `segment` against the cache root and throw when the result lands\n * outside it — the last line of defense against path traversal, independent\n * of how the key was encoded.\n */\n protected containedPath(segment: string): string {\n const base = path.resolve(this.directory);\n const resolved = path.resolve(base, segment);\n const relative = path.relative(base, resolved);\n\n if (relative === \"..\" || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {\n throw new CacheError(`Cache key resolves outside the cache directory: \"${segment}\"`);\n }\n\n return resolved;\n }\n\n /**\n * {@inheritdoc}\n *\n * Dotted keys (`ns.a`) are stored as sibling directories, not nested ones\n * (see {@link keyDirectory}) — a directory literally named `<namespace>`\n * rarely exists on its own. Namespace removal therefore has to scan the\n * cache root's immediate children and remove every directory whose\n * *logical* (decoded) name equals the namespace or starts with\n * `<namespace>.`, mirroring the `key = $1 OR key LIKE $2` boundary\n * semantics the `pg` driver already uses for the same contract.\n */\n public async removeNamespace(namespace: string) {\n const parsedNamespace = this.parseKey(namespace);\n\n this.log(\"clearing\", namespace);\n\n try {\n const root = this.containedPath(\"\");\n\n if (parsedNamespace === \"\") {\n await removeDirectoryAsync(root);\n this.log(\"cleared\", namespace);\n return this;\n }\n\n const prefix = `${parsedNamespace}.`;\n const entries = await listDirectoriesAsync(root).catch(() => [] as string[]);\n\n await Promise.all(\n entries.map(async (entryPath) => {\n const decoded = this.decodeKeySegment(path.basename(entryPath));\n\n if (decoded === parsedNamespace || decoded.startsWith(prefix)) {\n await removeDirectoryAsync(entryPath);\n }\n }),\n );\n\n this.log(\"cleared\", namespace);\n } catch (error) {\n //\n }\n\n return this;\n }\n\n /**\n * {@inheritdoc}\n *\n * `onConflict: \"create\"` is exclusive (temp file + hard link, so `lock()`\n * is safe across concurrent writers). `onConflict: \"update\"` is NOT atomic:\n * the existence probe and the write are separate steps.\n */\n public async set(\n key: CacheKey,\n value: any,\n ttlOrOptions?: CacheTtl | CacheSetOptions,\n ): Promise<any> {\n const parsedKey = this.parseKey(key);\n const { ttl, tags, onConflict, vector, staleAt } = this.resolveSetOptions(ttlOrOptions);\n\n if (vector) {\n throw new CacheUnsupportedError(\n \"'file' driver does not support similarity retrieval — use a memory driver, 'pg' (with pgvector), or 'redis' (with RediSearch).\",\n );\n }\n\n this.log(\"caching\", parsedKey);\n\n const existing =\n onConflict === \"upsert\" || onConflict === \"create\" ? null : await this.get(key);\n const exists = existing !== null;\n\n if (onConflict === \"update\" && !exists) {\n const result: CacheSetResult = { wasSet: false, existing: null };\n return result;\n }\n\n const data = this.prepareDataForStorage(value, ttl, staleAt);\n\n const fileDirectory = this.keyDirectory(parsedKey);\n\n await ensureDirectoryAsync(fileDirectory);\n\n const filePath = path.resolve(fileDirectory, this.fileName);\n\n if (onConflict === \"create\") {\n const conflict = await this.writeExclusive(filePath, data);\n\n if (conflict) {\n const result: CacheSetResult = { wasSet: false, existing: conflict.existing };\n return result;\n }\n } else {\n await atomicWriteJsonAsync(filePath, data);\n }\n\n if (tags && tags.length > 0) {\n await this.applyTags(key, tags);\n }\n\n this.log(\"cached\", parsedKey);\n\n await this.emit(\"set\", { key: parsedKey, value, ttl });\n\n if (onConflict === \"create\" || onConflict === \"update\") {\n const result: CacheSetResult = { wasSet: true, existing: null };\n return result;\n }\n\n return this;\n }\n\n /**\n * Create `filePath` only if it does not exist. Writes a temp file, then\n * hard-links it to the target (EEXIST = already present). An existing but\n * expired entry is removed (the file only, never the directory) and the\n * link retried once.\n *\n * Returns `null` when written, or `{ existing }` on conflict.\n */\n protected async writeExclusive(\n filePath: string,\n data: CacheData,\n ): Promise<{ existing: any } | null> {\n const tempPath = `${filePath}.${randomBytes(6).toString(\"hex\")}.tmp`;\n\n try {\n await fs.promises.writeFile(tempPath, JSON.stringify(data, null, 2));\n\n for (let attempt = 0; attempt < 2; attempt++) {\n try {\n await fs.promises.link(tempPath, filePath);\n return null;\n } catch (error: any) {\n if (error?.code !== \"EEXIST\") {\n throw error;\n }\n }\n\n let current: CacheData | undefined;\n\n try {\n current = (await getJsonFileAsync(filePath)) as CacheData | undefined;\n } catch {\n current = undefined;\n }\n\n const expired =\n current?.expiresAt !== undefined &&\n current.expiresAt !== null &&\n current.expiresAt <= Date.now();\n\n if (current && !expired) {\n return { existing: current.data ?? null };\n }\n\n if (attempt === 0 && expired) {\n await fs.promises.rm(filePath, { force: true });\n continue;\n }\n\n // Unreadable (corrupt) file: treat as held, never delete it.\n return { existing: null };\n }\n\n return { existing: null };\n } finally {\n await fs.promises.unlink(tempPath).catch(() => undefined);\n }\n }\n\n /**\n * {@inheritdoc}\n *\n * File driver does not yet ship with a file-lock primitive, so concurrent\n * writers could clobber each other. Rather than ship an unsafe default, we\n * throw — consumers can fall back to memory/redis for `update` until a\n * proper file lock lands (tracked in `domains/cache/backlog.md`).\n */\n public async update(): Promise<never> {\n throw new CacheUnsupportedError(\n \"`update()` is not supported on the file driver. Use the memory or redis driver, or wait for the file-lock primitive (see domains/cache/backlog.md).\",\n );\n }\n\n /**\n * {@inheritdoc}\n */\n public async merge(): Promise<never> {\n throw new CacheUnsupportedError(\n \"`merge()` is not supported on the file driver. Use the memory or redis driver.\",\n );\n }\n\n /**\n * Read the raw {@link CacheData} wrapper from disk, including `staleAt`\n * metadata. Returns `null` for missing or expired files — `swr()`\n * consumes this to branch on freshness.\n */\n protected async getEntry(key: CacheKey): Promise<CacheData | null> {\n const parsedKey = this.parseKey(key);\n const fileDirectory = this.keyDirectory(parsedKey);\n\n try {\n const entry = (await getJsonFileAsync(path.resolve(fileDirectory, this.fileName))) as\n | CacheData\n | undefined;\n\n if (!entry) {\n return null;\n }\n\n // `Infinity` (no expiry) is written to JSON as `null`; `null <= now`\n // is true, so only a real deadline may count as expired.\n if (typeof entry.expiresAt === \"number\" && entry.expiresAt <= Date.now()) {\n return null;\n }\n\n return entry;\n } catch {\n return null;\n }\n }\n\n /**\n * {@inheritdoc}\n */\n public async get(key: CacheKey) {\n const parsedKey = this.parseKey(key);\n\n this.log(\"fetching\", parsedKey);\n\n const fileDirectory = this.keyDirectory(parsedKey);\n\n let value: CacheData | undefined;\n\n try {\n value = (await getJsonFileAsync(path.resolve(fileDirectory, this.fileName))) as\n | CacheData\n | undefined;\n } catch {\n // Missing file (ENOENT) or corrupt JSON: a plain miss. Never remove the\n // directory here — it may be mid-write by another process.\n value = undefined;\n }\n\n if (value === undefined || value === null || typeof value !== \"object\") {\n this.log(\"notFound\", parsedKey);\n await this.emit(\"miss\", { key: parsedKey });\n return null;\n }\n\n // Only a successfully parsed but expired entry is removed (inside\n // parseCachedData).\n const result = await this.parseCachedData(parsedKey, value);\n\n if (result === null) {\n await this.emit(\"miss\", { key: parsedKey });\n } else {\n await this.emit(\"hit\", { key: parsedKey, value: result });\n }\n\n return result;\n }\n\n /**\n * {@inheritdoc}\n */\n public async remove(key: CacheKey) {\n const parsedKey = this.parseKey(key);\n this.log(\"removing\", parsedKey);\n\n const fileDirectory = this.keyDirectory(parsedKey);\n\n try {\n await removeDirectoryAsync(fileDirectory);\n\n this.log(\"removed\", parsedKey);\n // Emit removed event\n await this.emit(\"removed\", { key: parsedKey });\n } catch (error) {\n //\n }\n }\n\n /**\n * {@inheritdoc}\n */\n public async flush() {\n this.log(\"flushing\");\n\n if (this.options.globalPrefix) {\n await this.removeNamespace(\"\");\n } else {\n await removeDirectoryAsync(this.directory);\n }\n\n this.log(\"flushed\");\n\n // Emit flushed event\n await this.emit(\"flushed\");\n }\n\n /**\n * {@inheritdoc}\n */\n public async connect() {\n this.log(\"connecting\");\n await ensureDirectoryAsync(this.directory);\n this.log(\"connected\");\n await this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,qBAAqB,aAAa;GAExC,KAAK,IAAI,WAAW,SAAS;GAE7B,MAAM,KAAK,KAAK,WAAW,EAAE,KAAK,UAAU,CAAC;EAC/C,SAAS,OAAO,CAEhB;CACF;;;;CAKA,MAAa,QAAQ;EACnB,KAAK,IAAI,UAAU;EAEnB,IAAI,KAAK,QAAQ,cACf,MAAM,KAAK,gBAAgB,EAAE;OAE7B,MAAM,qBAAqB,KAAK,SAAS;EAG3C,KAAK,IAAI,SAAS;EAGlB,MAAM,KAAK,KAAK,SAAS;CAC3B;;;;CAKA,MAAa,UAAU;EACrB,KAAK,IAAI,YAAY;EACrB,MAAM,qBAAqB,KAAK,SAAS;EACzC,KAAK,IAAI,WAAW;EACpB,MAAM,KAAK,KAAK,WAAW;CAC7B;AACF"}
|
|
1
|
+
{"version":3,"file":"file-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/file-cache-driver.ts"],"mappings":";;;;;;;;;;;;AA2BA,MAAM,qBAAqB;;;;;AAM3B,MAAM,iBAAiB;AAEvB,IAAa,kBAAb,cACU,gBAEV;;;cAIgB;;;;;CAKd,AAAO,WAAW,SAA2B;EAC3C,IAAI,CAAC,QAAQ,WACX,MAAM,IAAI,wBACR,2DACF;EAGF,OAAO,MAAM,WAAW,OAAO;CACjC;;;;CAKA,IAAW,YAAY;EACrB,MAAM,YAAY,KAAK,QAAQ;EAE/B,IAAI,OAAO,cAAc,YACvB,OAAO,UAAU;EAGnB,MAAM,IAAI,wBACR,6EACF;CACF;;;;CAKA,IAAW,WAAW;EACpB,MAAM,WAAW,KAAK,QAAQ;EAE9B,IAAI,OAAO,aAAa,YACtB,OAAO,SAAS;EAGlB,OAAO;CACT;;;;;;;;;;;CAYA,AAAU,aAAa,WAA2B;EAGhD,IAAI,cAAc,IAChB,MAAM,IAAI,wBAAwB,8BAA8B;EAGlE,OAAO,KAAK,cAAc,KAAK,iBAAiB,SAAS,CAAC;CAC5D;;;;;CAMA,AAAU,iBAAiB,WAA2B;E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CAAC;EAG1D,OAAO;CACT;;;;CAKA,MAAa,OAAO,KAAe;EACjC,MAAM,KAAK,aAAa,KAAK,SAAS,GAAG,CAAC;CAC5C;;;;CAKA,MAAgB,aAAa,WAAkC;EAC7D,KAAK,IAAI,YAAY,SAAS;EAE9B,MAAM,gBAAgB,KAAK,aAAa,SAAS;EAEjD,IAAI;GACF,MAAM,qBAAqB,aAAa;GAExC,KAAK,IAAI,WAAW,SAAS;GAE7B,MAAM,KAAK,KAAK,WAAW,EAAE,KAAK,UAAU,CAAC;EAC/C,SAAS,OAAO,CAEhB;CACF;;;;CAKA,MAAa,QAAQ;EACnB,KAAK,IAAI,UAAU;EAEnB,IAAI,KAAK,QAAQ,cACf,MAAM,KAAK,gBAAgB,EAAE;OAE7B,MAAM,qBAAqB,KAAK,SAAS;EAG3C,KAAK,IAAI,SAAS;EAGlB,MAAM,KAAK,KAAK,SAAS;CAC3B;;;;CAKA,MAAa,UAAU;EACrB,KAAK,IAAI,YAAY;EACrB,MAAM,qBAAqB,KAAK,SAAS;EACzC,KAAK,IAAI,WAAW;EACpB,MAAM,KAAK,KAAK,WAAW;CAC7B;AACF;;;;;AAMA,SAAS,eAAe,OAA2B;CACjD,OAAO,OAAO,MAAM,cAAc,YAAY,MAAM,aAAa,KAAK,IAAI;AAC5E;AAEA,SAAS,cAAc,OAAoC;CACzD,IAAI,OAAO,SAAS,UAAU,MAAM;AACtC;AAEA,SAAS,MAAM,IAA2B;CACxC,OAAO,IAAI,SAAS,YAAY,WAAW,SAAS,EAAE,CAAC;AACzD"}
|
|
@@ -20,6 +20,11 @@ export declare class InMemoryTagIndex {
|
|
|
20
20
|
* The members of a tag set (a copy; empty when the set does not exist).
|
|
21
21
|
*/
|
|
22
22
|
members(tagKey: string): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Up to `count` members of a tag set from a random starting point, without
|
|
25
|
+
* copying the whole set.
|
|
26
|
+
*/
|
|
27
|
+
sample(tagKey: string, count: number): string[];
|
|
23
28
|
/**
|
|
24
29
|
* Remove members from a tag set; an emptied set is dropped.
|
|
25
30
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-tag-index.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/in-memory-tag-index.ts"],"mappings":";;;;;;;;;;;;qBAWa;qBACQ,MAAM,YAAY;;;;EAK9B,IAAI,gBAAgB;;;;EAoBpB,QAAQ;;;;
|
|
1
|
+
{"version":3,"file":"in-memory-tag-index.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/in-memory-tag-index.ts"],"mappings":";;;;;;;;;;;;qBAWa;qBACQ,MAAM,YAAY;;;;EAK9B,IAAI,gBAAgB;;;;EAoBpB,QAAQ;;;;;EAQR,OAAO,gBAAgB;;;;EAyBvB,OAAO,gBAAgB;;;;EAmBvB,OAAO;;;;;;EASP,gBAAgB;;;;EAmBhB"}
|
|
@@ -33,6 +33,23 @@ var InMemoryTagIndex = class {
|
|
|
33
33
|
return [...this.sets.get(tagKey) ?? []];
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
+
* Up to `count` members of a tag set from a random starting point, without
|
|
37
|
+
* copying the whole set.
|
|
38
|
+
*/
|
|
39
|
+
sample(tagKey, count) {
|
|
40
|
+
const set = this.sets.get(tagKey);
|
|
41
|
+
if (!set || count <= 0) return [];
|
|
42
|
+
const skip = set.size > count ? Math.floor(Math.random() * (set.size - count + 1)) : 0;
|
|
43
|
+
const picked = [];
|
|
44
|
+
let index = 0;
|
|
45
|
+
for (const member of set) {
|
|
46
|
+
if (index++ < skip) continue;
|
|
47
|
+
picked.push(member);
|
|
48
|
+
if (picked.length >= count) break;
|
|
49
|
+
}
|
|
50
|
+
return picked;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
36
53
|
* Remove members from a tag set; an emptied set is dropped.
|
|
37
54
|
*/
|
|
38
55
|
remove(tagKey, members) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-tag-index.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/in-memory-tag-index.ts"],"
|
|
1
|
+
{"version":3,"file":"in-memory-tag-index.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/in-memory-tag-index.ts"],"mappings":";;;;;;;;;;;;AAWA,IAAa,mBAAb,MAA8B;;8BACwB,IAAI,IAAI;;;;;CAK5D,AAAO,IAAI,QAAgB,SAAkC;EAC3D,IAAI,QAAQ,WAAW,GACrB;EAGF,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM;EAE9B,IAAI,CAAC,KAAK;GACR,sBAAM,IAAI,IAAI;GACd,KAAK,KAAK,IAAI,QAAQ,GAAG;EAC3B;EAEA,KAAK,MAAM,UAAU,SACnB,IAAI,IAAI,MAAM;CAElB;;;;CAKA,AAAO,QAAQ,QAA0B;EACvC,OAAO,CAAC,GAAI,KAAK,KAAK,IAAI,MAAM,KAAK,CAAC,CAAE;CAC1C;;;;;CAMA,AAAO,OAAO,QAAgB,OAAyB;EACrD,MAAM,MAAM,KAAK,KAAK,IAAI,MAAM;EAEhC,IAAI,CAAC,OAAO,SAAS,GACnB,OAAO,CAAC;EAGV,MAAM,OAAO,IAAI,OAAO,QAAQ,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI,OAAO,QAAQ,EAAE,IAAI;EACrF,MAAM,SAAmB,CAAC;EAC1B,IAAI,QAAQ;EAEZ,KAAK,MAAM,UAAU,KAAK;GACxB,IAAI,UAAU,MAAM;GAEpB,OAAO,KAAK,MAAM;GAElB,IAAI,OAAO,UAAU,OAAO;EAC9B;EAEA,OAAO;CACT;;;;CAKA,AAAO,OAAO,QAAgB,SAAkC;EAC9D,MAAM,MAAM,KAAK,KAAK,IAAI,MAAM;EAEhC,IAAI,CAAC,KACH;EAGF,KAAK,MAAM,UAAU,SACnB,IAAI,OAAO,MAAM;EAGnB,IAAI,IAAI,SAAS,GACf,KAAK,KAAK,OAAO,MAAM;CAE3B;;;;CAKA,AAAO,OAAO,QAAsB;EAClC,KAAK,KAAK,OAAO,MAAM;CACzB;;;;;;CAOA,AAAO,gBAAgB,WAAyB;EAC9C,IAAI,cAAc,IAAI;GACpB,KAAK,KAAK,MAAM;GAEhB;EACF;EAEA,MAAM,SAAS,YAAY;EAE3B,KAAK,MAAM,OAAO,CAAC,GAAG,KAAK,KAAK,KAAK,CAAC,GACpC,IAAI,QAAQ,aAAa,IAAI,WAAW,MAAM,GAC5C,KAAK,KAAK,OAAO,GAAG;CAG1B;;;;CAKA,AAAO,QAAc;EACnB,KAAK,KAAK,MAAM;CAClB;AACF"}
|
|
@@ -2,7 +2,7 @@ import { BaseCacheDriver } from "./base-cache-driver.mjs";
|
|
|
2
2
|
import { CacheStructuresBackend, StructuresCapable } from "../structures/types.mjs";
|
|
3
3
|
import { MemoryStructuresBackend } from "../structures/memory-structures-backend.mjs";
|
|
4
4
|
import { InMemoryTagIndex } from "./in-memory-tag-index.mjs";
|
|
5
|
-
import { CacheData, CacheDriver, CacheKey, CacheSetOptions, CacheSimilarHit, CacheSimilarOptions, CacheTtl, LRUMemoryCacheOptions } from "../types.mjs";
|
|
5
|
+
import { CacheData, CacheDriver, CacheKey, CacheSetOptions, CacheSimilarHit, CacheSimilarOptions, CacheSwrOptions, CacheTtl, LRUMemoryCacheOptions } from "../types.mjs";
|
|
6
6
|
//#region ../../packages/cache/src/drivers/lru-memory-cache-driver.d.ts
|
|
7
7
|
declare class CacheNode {
|
|
8
8
|
key: string;
|
|
@@ -110,6 +110,13 @@ export declare class LRUMemoryCacheDriver extends BaseCacheDriver<LRUMemoryCache
|
|
|
110
110
|
* path.
|
|
111
111
|
*/
|
|
112
112
|
protected getEntry(key: CacheKey): Promise<CacheData | null>;
|
|
113
|
+
/**
|
|
114
|
+
* {@inheritdoc}
|
|
115
|
+
*
|
|
116
|
+
* This driver stores the written value by reference, so the callers of a
|
|
117
|
+
* cold-miss fetch get a copy rather than the stored object itself.
|
|
118
|
+
*/
|
|
119
|
+
protected swrFetchAndStore<T>(key: CacheKey, options: CacheSwrOptions, callback: () => Promise<T>, freshSeconds: number, staleSeconds: number): Promise<T>;
|
|
113
120
|
/**
|
|
114
121
|
* Live node for `parsedKey`, or `undefined` when missing / expired (an
|
|
115
122
|
* expired node is unlinked). Synchronous.
|
|
@@ -164,6 +171,16 @@ export declare class LRUMemoryCacheDriver extends BaseCacheDriver<LRUMemoryCache
|
|
|
164
171
|
* {@inheritdoc}
|
|
165
172
|
*/
|
|
166
173
|
tagDelete(tagKey: CacheKey): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* {@inheritdoc}
|
|
176
|
+
*/
|
|
177
|
+
tagSample(tagKey: CacheKey, count: number): Promise<string[]>;
|
|
178
|
+
/**
|
|
179
|
+
* {@inheritdoc}
|
|
180
|
+
*
|
|
181
|
+
* A synchronous lookup: no copy, no events, no recency or TTL change.
|
|
182
|
+
*/
|
|
183
|
+
exists(key: CacheKey): Promise<boolean>;
|
|
167
184
|
/**
|
|
168
185
|
* {@inheritdoc}
|
|
169
186
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lru-memory-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/lru-memory-cache-driver.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"lru-memory-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/lru-memory-cache-driver.ts"],"mappings":";;;;;;cAoBM;EAeK;EACA;EAfF,MAAM;EACN,MAAM;EACN;;;;;EAKA;;;;;EAKA;EACP,YACS,aACA,YACP;MAOS;;;;;;;;qBAWA,6BACH,gBAAgB,sBAAsB,kCACnC,YAAY,sBAAsB,wBAAwB;;;;EAK9D;;;;YAKG,OAAO,YAAY;;;;YAKnB,UAAU;;;;YAKV,MAAM;;;;YAKN,MAAM;;;;YAKN,kBAAkB,OAAO;;;;EAKnC;;;;EAUO;;;;EAQA;;;;;;;;;EAwCM,gBAAgB,oBAAiB;;;;YA2CpC,iBAAiB;;;;EAKpB,qBAAqB;;;;EASf,IACX,KAAK,UACL,YACA,eAAe,WAAW,kBACzB;;;;YA8EO,SAAS,MAAM;;;;YAQf,WAAW,MAAM;;;;YAQjB,QAAQ,MAAM;;;;YAUd;;;;;;;YAcM,SAAS,KAAK,WAAW,QAAQ;;;;;;;YAuBjC,iBAAiB,GAC/B,KAAK,UACL,SAAS,iBACT,gBAAgB,QAAQ,IACxB,sBACA,uBACC,QAAQ;;;;;YAUD,SAAS,oBAAoB;;;;;;;;EAwB1B,UACX,KAAK,UACL,gBACA;IAAW,MAAM;MAChB;;;;;;EA4CU,OAAO,KAAK,UAAU,KAAK,WAAW;;;;;;;EAoBtC,KAAK,KAAK,WAAW;;;;EA2BrB,IAAI,KAAK,WAAQ;;;;EA0DjB,OAAO,KAAK,WAAQ;;;;;;EAuBpB,OAAO,QAAQ,UAAU,oBAAoB;;;;EAO7C,WAAW,QAAQ,WAAW;;;;EAO9B,UAAU,QAAQ,UAAU,oBAAoB;;;;EAOhD,UAAU,QAAQ,WAAW;;;;EAO7B,UAAU,QAAQ,UAAU,gBAAgB;;;;;;EAS5C,OAAO,KAAK,WAAW;;;;;;;;EAWvB,SAAK;;;;;;;;;;EA0BL,QAAQ,SACnB,kBACA,SAAS,sBACR,QAAQ,gBAAgB;;;;MAwChB;;;;EAOE,cAAU"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cosineSimilarity, parseTtl } from "../utils.mjs";
|
|
2
2
|
import { MemoryStructuresBackend } from "../structures/memory-structures-backend.mjs";
|
|
3
3
|
import { BaseCacheDriver } from "./base-cache-driver.mjs";
|
|
4
|
+
import { cloneValue } from "./clone-value.mjs";
|
|
4
5
|
import { InMemoryTagIndex } from "./in-memory-tag-index.mjs";
|
|
5
6
|
import { maskEmailsInText } from "@warlock.js/logger";
|
|
6
7
|
|
|
@@ -120,7 +121,7 @@ var LRUMemoryCacheDriver = class extends BaseCacheDriver {
|
|
|
120
121
|
const exists = Boolean(existingNode);
|
|
121
122
|
if (onConflict === "create" && exists) return {
|
|
122
123
|
wasSet: false,
|
|
123
|
-
existing: existingNode.value
|
|
124
|
+
existing: cloneValue(existingNode.value)
|
|
124
125
|
};
|
|
125
126
|
if (onConflict === "update" && !exists) return {
|
|
126
127
|
wasSet: false,
|
|
@@ -196,12 +197,22 @@ var LRUMemoryCacheDriver = class extends BaseCacheDriver {
|
|
|
196
197
|
const node = this.cache.get(parsedKey);
|
|
197
198
|
if (!node || node.isExpired) return null;
|
|
198
199
|
return {
|
|
199
|
-
data: node.value,
|
|
200
|
+
data: cloneValue(node.value),
|
|
200
201
|
expiresAt: node.expiresAt,
|
|
201
202
|
staleAt: node.staleAt
|
|
202
203
|
};
|
|
203
204
|
}
|
|
204
205
|
/**
|
|
206
|
+
* {@inheritdoc}
|
|
207
|
+
*
|
|
208
|
+
* This driver stores the written value by reference, so the callers of a
|
|
209
|
+
* cold-miss fetch get a copy rather than the stored object itself.
|
|
210
|
+
*/
|
|
211
|
+
async swrFetchAndStore(key, options, callback, freshSeconds, staleSeconds) {
|
|
212
|
+
const result = await super.swrFetchAndStore(key, options, callback, freshSeconds, staleSeconds);
|
|
213
|
+
return cloneValue(result);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
205
216
|
* Live node for `parsedKey`, or `undefined` when missing / expired (an
|
|
206
217
|
* expired node is unlinked). Synchronous.
|
|
207
218
|
*/
|
|
@@ -368,6 +379,20 @@ var LRUMemoryCacheDriver = class extends BaseCacheDriver {
|
|
|
368
379
|
}
|
|
369
380
|
/**
|
|
370
381
|
* {@inheritdoc}
|
|
382
|
+
*/
|
|
383
|
+
async tagSample(tagKey, count) {
|
|
384
|
+
return this.tagIndex.sample(this.parseKey(tagKey), count);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* {@inheritdoc}
|
|
388
|
+
*
|
|
389
|
+
* A synchronous lookup: no copy, no events, no recency or TTL change.
|
|
390
|
+
*/
|
|
391
|
+
async exists(key) {
|
|
392
|
+
return this.liveNode(this.parseKey(key)) !== void 0;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* {@inheritdoc}
|
|
371
396
|
*
|
|
372
397
|
* When a `globalPrefix` is configured, `flush` scopes itself to that prefix
|
|
373
398
|
* so multi-tenant caches don't accidentally wipe sibling tenants. Without
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lru-memory-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/lru-memory-cache-driver.ts"],"sourcesContent":["import { maskEmailsInText } from \"@warlock.js/logger\";\nimport type {\n CacheData,\n CacheDriver,\n CacheKey,\n CacheSetOptions,\n CacheSetResult,\n CacheSimilarHit,\n CacheSimilarOptions,\n CacheTtl,\n LRUMemoryCacheOptions,\n} from \"../types\";\nimport { cosineSimilarity, parseTtl } from \"../utils\";\nimport { BaseCacheDriver } from \"./base-cache-driver\";\nimport { MemoryStructuresBackend } from \"../structures/memory-structures-backend\";\nimport type { CacheStructuresBackend, StructuresCapable } from \"../structures/types\";\nimport { InMemoryTagIndex } from \"./in-memory-tag-index\";\n\nclass CacheNode {\n public next: CacheNode | null = null;\n public prev: CacheNode | null = null;\n public expiresAt?: number;\n /**\n * Freshness deadline (ms timestamp) — populated by `swr()`. Within\n * `expiresAt > now > staleAt` the entry is \"stale-but-revalidatable.\"\n */\n public staleAt?: number;\n /**\n * Optional embedding vector — populated when the entry was written with\n * `set({ vector })`. Scanned by `similar()`.\n */\n public vector?: number[];\n public constructor(\n public key: string,\n public value: any,\n ttl?: number,\n ) {\n if (ttl && ttl !== Infinity) {\n this.expiresAt = Date.now() + ttl * 1000;\n }\n }\n\n public get isExpired(): boolean {\n return this.expiresAt !== undefined && this.expiresAt < Date.now();\n }\n}\n\n/**\n * LRU Memory Cache Driver\n * The concept of LRU is to remove the least recently used data\n * whenever the cache is full\n * The question that resides here is how to tell the cache is full?\n */\nexport class LRUMemoryCacheDriver\n extends BaseCacheDriver<LRUMemoryCacheDriver, LRUMemoryCacheOptions>\n implements CacheDriver<LRUMemoryCacheDriver, LRUMemoryCacheOptions>, StructuresCapable\n{\n /**\n * {@inheritdoc}\n */\n public name = \"lru\";\n\n /**\n * Cache map\n */\n protected cache: Map<string, CacheNode> = new Map();\n\n /**\n * Tag index, kept out of the LRU list so capacity pressure can never evict it.\n */\n protected tagIndex: InMemoryTagIndex = new InMemoryTagIndex();\n\n /**\n * Head of the cache\n */\n protected head: CacheNode = new CacheNode(\"\", null);\n\n /**\n * Tail of the cache\n */\n protected tail: CacheNode = new CacheNode(\"\", null);\n\n /**\n * Cleanup interval reference\n */\n protected cleanupInterval?: NodeJS.Timeout;\n\n /**\n * {@inheritdoc}\n */\n public constructor() {\n super();\n\n this.init();\n this.startCleanup();\n }\n\n /**\n * Initialize the cache\n */\n public init() {\n this.head.next = this.tail;\n this.tail.prev = this.head;\n }\n\n /**\n * Start the cleanup process for expired items\n */\n public startCleanup() {\n // Clear existing interval if any\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval);\n }\n\n this.cleanupInterval = setInterval(async () => {\n const now = Date.now();\n const expiredKeys: string[] = [];\n\n for (const [key, node] of this.cache) {\n if (node.expiresAt && node.expiresAt <= now) {\n expiredKeys.push(key);\n }\n }\n\n for (const key of expiredKeys) {\n const node = this.cache.get(key);\n if (node) {\n this.removeNode(node);\n this.cache.delete(key);\n this.log(\"expired\", key);\n // Emit expired event\n await this.emit(\"expired\", { key });\n }\n }\n }, 1000);\n\n // do not block the process from exiting\n this.cleanupInterval.unref();\n }\n\n /**\n * {@inheritdoc}\n *\n * Clears every entry whose key starts with the parsed namespace (followed\n * by a dot) or equals it exactly. Called with an empty namespace while a\n * `globalPrefix` is configured, clears everything under the prefix — which\n * is how `flush()` scopes cleanup per tenant.\n */\n public async removeNamespace(namespace: string) {\n const parsedNamespace = this.parseKey(namespace);\n\n this.log(\"clearing\", parsedNamespace || \"(all)\");\n\n const removed: string[] = [];\n\n this.tagIndex.removeNamespace(parsedNamespace);\n\n if (parsedNamespace === \"\") {\n this.structureStore?.clear();\n for (const key of this.cache.keys()) {\n removed.push(key);\n }\n } else {\n const prefix = parsedNamespace + \".\";\n\n this.structureStore?.clearPrefix(prefix);\n\n for (const key of this.cache.keys()) {\n if (key === parsedNamespace || key.startsWith(prefix)) {\n removed.push(key);\n }\n }\n }\n\n for (const key of removed) {\n const node = this.cache.get(key);\n if (node) {\n this.removeNode(node);\n this.cache.delete(key);\n }\n await this.emit(\"removed\", { key });\n }\n\n this.log(\"cleared\", parsedNamespace || \"(all)\");\n\n return removed;\n }\n\n /**\n * Backing store of `cache.structures`, created on first use.\n */\n protected structureStore?: MemoryStructuresBackend;\n\n /**\n * {@inheritdoc}\n */\n public structuresBackend(): CacheStructuresBackend {\n this.structureStore ??= new MemoryStructuresBackend((key) => this.parseKey(key));\n\n return this.structureStore;\n }\n\n /**\n * {@inheritdoc}\n */\n public async set(\n key: CacheKey,\n value: any,\n ttlOrOptions?: CacheTtl | CacheSetOptions,\n ): Promise<any> {\n const parsedKey = this.parseKey(key);\n const { ttl, tags, onConflict, vector, staleAt } = this.resolveSetOptions(ttlOrOptions);\n\n this.log(\"caching\", parsedKey);\n\n // For conditional writes, check existence via get() so expired entries\n // are treated as missing (get() handles expiry cleanup). The raw `cache.get`\n // node lookup would let stale entries block onConflict: \"create\".\n let existingNode = this.cache.get(parsedKey);\n if (existingNode && existingNode.isExpired) {\n this.removeNode(existingNode);\n this.cache.delete(parsedKey);\n existingNode = undefined;\n }\n\n const exists = Boolean(existingNode);\n\n if (onConflict === \"create\" && exists) {\n const result: CacheSetResult = {\n wasSet: false,\n existing: existingNode!.value,\n };\n return result;\n }\n\n if (onConflict === \"update\" && !exists) {\n const result: CacheSetResult = { wasSet: false, existing: null };\n return result;\n }\n\n if (existingNode) {\n existingNode.value = value;\n if (ttl && ttl !== Infinity) {\n existingNode.expiresAt = Date.now() + ttl * 1000;\n } else {\n existingNode.expiresAt = undefined;\n }\n existingNode.staleAt = staleAt;\n if (vector) {\n existingNode.vector = vector.slice();\n }\n\n this.moveHead(existingNode);\n } else {\n const newNode = new CacheNode(parsedKey, value, ttl);\n newNode.staleAt = staleAt;\n if (vector) {\n newNode.vector = vector.slice();\n }\n\n this.cache.set(parsedKey, newNode);\n\n this.addNode(newNode);\n if (this.cache.size > this.capacity) {\n this.removeTail();\n }\n }\n\n if (tags && tags.length > 0) {\n await this.applyTags(key, tags);\n }\n\n this.log(\"cached\", parsedKey);\n\n await this.emit(\"set\", { key: parsedKey, value, ttl });\n\n if (onConflict === \"create\" || onConflict === \"update\") {\n const result: CacheSetResult = { wasSet: true, existing: null };\n return result;\n }\n\n return this;\n }\n\n /**\n * Move the node to the head\n */\n protected moveHead(node: CacheNode) {\n this.removeNode(node);\n this.addNode(node);\n }\n\n /**\n * Remove the node from the cache\n */\n protected removeNode(node: CacheNode) {\n node.prev!.next = node.next;\n node.next!.prev = node.prev;\n }\n\n /**\n * Add the node to the head\n */\n protected addNode(node: CacheNode) {\n node.next = this.head.next;\n node.prev = this.head;\n this.head.next!.prev = node;\n this.head.next = node;\n }\n\n /**\n * Remove the tail node\n */\n protected removeTail() {\n const node = this.tail.prev!;\n\n this.removeNode(node);\n\n this.cache.delete(node.key);\n }\n\n /**\n * Read the raw {@link CacheData} wrapper, including `staleAt` metadata.\n * Returns `null` for missing or expired nodes — `swr()` consumes this\n * to branch on freshness without going through `get()`'s clone-and-emit\n * path.\n */\n protected async getEntry(key: CacheKey): Promise<CacheData | null> {\n const parsedKey = this.parseKey(key);\n const node = this.cache.get(parsedKey);\n\n if (!node || node.isExpired) {\n return null;\n }\n\n return {\n data: node.value,\n expiresAt: node.expiresAt,\n staleAt: node.staleAt,\n };\n }\n\n /**\n * Live node for `parsedKey`, or `undefined` when missing / expired (an\n * expired node is unlinked). Synchronous.\n */\n protected liveNode(parsedKey: string): CacheNode | undefined {\n const node = this.cache.get(parsedKey);\n\n if (!node) {\n return undefined;\n }\n\n if (node.isExpired) {\n this.removeNode(node);\n this.cache.delete(parsedKey);\n\n return undefined;\n }\n\n return node;\n }\n\n /**\n * {@inheritdoc}\n *\n * Read, add and write run synchronously (no `await` in between), so\n * concurrent increments in this process never lose an update. An existing\n * node keeps its expiry; a missing key starts from 0 with the default TTL.\n */\n public async increment(\n key: CacheKey,\n value: number = 1,\n options: { ttl?: CacheTtl } = {},\n ): Promise<number> {\n const ttl = options.ttl === undefined ? this.ttl : parseTtl(options.ttl);\n const parsedKey = this.parseKey(key);\n const node = this.liveNode(parsedKey);\n const current = node ? node.value : 0;\n\n if (typeof current !== \"number\") {\n throw new Error(`Cannot increment non-numeric value for key: ${maskEmailsInText(parsedKey)}`);\n }\n\n const newValue = current + value;\n\n if (node) {\n node.value = newValue;\n if (\n options.ttl !== undefined &&\n !Number.isFinite(node.expiresAt) &&\n Number.isFinite(ttl) &&\n ttl > 0\n ) {\n node.expiresAt = Date.now() + ttl * 1000;\n }\n this.moveHead(node);\n } else {\n const newNode = new CacheNode(parsedKey, newValue, ttl);\n\n this.cache.set(parsedKey, newNode);\n this.addNode(newNode);\n\n if (this.cache.size > this.capacity) {\n this.removeTail();\n }\n }\n\n await this.emit(\"set\", { key: parsedKey, value: newValue, ttl });\n\n return newValue;\n }\n\n /**\n * {@inheritdoc}\n *\n * The deadline moves in place, synchronously.\n */\n public async extend(key: CacheKey, ttl: CacheTtl): Promise<boolean> {\n const seconds = this.resolveExtendTtl(ttl);\n const node = this.liveNode(this.parseKey(key));\n\n if (!node) {\n return false;\n }\n\n node.expiresAt = Number.isFinite(seconds) ? Date.now() + seconds * 1000 : undefined;\n this.moveHead(node);\n\n return true;\n }\n\n /**\n * {@inheritdoc}\n *\n * Read and unlink run synchronously, so a value is handed out exactly once\n * even when concurrent callers pull the same key.\n */\n public async pull(key: CacheKey): Promise<any | null> {\n const parsedKey = this.parseKey(key);\n const node = this.liveNode(parsedKey);\n\n if (!node) {\n await this.emit(\"miss\", { key: parsedKey });\n\n return null;\n }\n\n this.removeNode(node);\n this.cache.delete(parsedKey);\n\n const value =\n node.value !== null && typeof node.value === \"object\"\n ? structuredClone(node.value)\n : node.value;\n\n await this.emit(\"hit\", { key: parsedKey, value });\n await this.emit(\"removed\", { key: parsedKey });\n\n return value;\n }\n\n /**\n * {@inheritdoc}\n */\n public async get(key: CacheKey) {\n const parsedKey = this.parseKey(key);\n\n this.log(\"fetching\", parsedKey);\n\n const node = this.cache.get(parsedKey);\n\n if (!node) {\n this.log(\"notFound\", parsedKey);\n // Emit miss event\n await this.emit(\"miss\", { key: parsedKey });\n return null;\n }\n\n // Check if expired\n if (node.isExpired) {\n this.removeNode(node);\n this.cache.delete(parsedKey);\n this.log(\"expired\", parsedKey);\n // Emit expired event\n await this.emit(\"expired\", { key: parsedKey });\n // Also emit miss since we're returning null\n await this.emit(\"miss\", { key: parsedKey });\n return null;\n }\n\n this.moveHead(node);\n\n this.log(\"fetched\", parsedKey);\n\n const value = node.value;\n\n // Apply cloning for immutability protection\n if (value === null || value === undefined) {\n return value;\n }\n\n const type = typeof value;\n if (type === \"string\" || type === \"number\" || type === \"boolean\") {\n // Emit hit event\n await this.emit(\"hit\", { key: parsedKey, value });\n return value;\n }\n\n try {\n const clonedValue = structuredClone(value);\n // Emit hit event\n await this.emit(\"hit\", { key: parsedKey, value: clonedValue });\n return clonedValue;\n } catch (error) {\n this.logError(`Failed to clone cached value for ${parsedKey}`, error);\n throw error;\n }\n }\n\n /**\n * {@inheritdoc}\n */\n public async remove(key: CacheKey) {\n const parsedKey = this.parseKey(key);\n\n this.log(\"removing\", parsedKey);\n\n const node = this.cache.get(parsedKey);\n\n if (node) {\n this.removeNode(node);\n this.cache.delete(parsedKey);\n }\n\n this.log(\"removed\", parsedKey);\n\n // Emit removed event\n await this.emit(\"removed\", { key: parsedKey });\n }\n\n /**\n * {@inheritdoc}\n *\n * Synchronous in-process set, never evicted or expired with the entries.\n */\n public async tagAdd(tagKey: CacheKey, members: string[]): Promise<void> {\n this.tagIndex.add(this.parseKey(tagKey), members);\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagMembers(tagKey: CacheKey): Promise<string[]> {\n return this.tagIndex.members(this.parseKey(tagKey));\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagRemove(tagKey: CacheKey, members: string[]): Promise<void> {\n this.tagIndex.remove(this.parseKey(tagKey), members);\n }\n\n /**\n * {@inheritdoc}\n */\n public async tagDelete(tagKey: CacheKey): Promise<void> {\n this.tagIndex.delete(this.parseKey(tagKey));\n }\n\n /**\n * {@inheritdoc}\n *\n * When a `globalPrefix` is configured, `flush` scopes itself to that prefix\n * so multi-tenant caches don't accidentally wipe sibling tenants. Without\n * a prefix, clears everything.\n */\n public async flush() {\n this.log(\"flushing\");\n\n if (this.options.globalPrefix) {\n await this.removeNamespace(\"\");\n } else {\n this.cache.clear();\n this.tagIndex.clear();\n this.structureStore?.clear();\n this.init();\n }\n\n this.log(\"flushed\");\n\n await this.emit(\"flushed\");\n }\n\n /**\n * {@inheritdoc}\n *\n * Brute-force O(N) cosine similarity over every cached node that carries a\n * vector. Suitable for development and small in-memory knowledge bases —\n * not for production beyond ~10k entries.\n *\n * @warning Dev-only — O(N) per query.\n */\n public async similar<T = any>(\n vector: number[],\n options: CacheSimilarOptions,\n ): Promise<CacheSimilarHit<T>[]> {\n const tagFilter = await this.getKeysForTags(options.tags);\n\n const hits: CacheSimilarHit<T>[] = [];\n\n for (const [parsedKey, node] of this.cache) {\n if (!node.vector) continue;\n if (node.isExpired) continue;\n if (tagFilter && !tagFilter.has(parsedKey)) continue;\n\n const score = cosineSimilarity(vector, node.vector);\n\n if (options.threshold !== undefined && score < options.threshold) {\n continue;\n }\n\n // Clone object values to match get() semantics.\n let value: any = node.value;\n if (value !== null && value !== undefined) {\n const t = typeof value;\n if (t !== \"string\" && t !== \"number\" && t !== \"boolean\") {\n value = structuredClone(value);\n }\n }\n\n hits.push({ key: parsedKey, value, score });\n }\n\n hits.sort((a, b) => b.score - a.score);\n\n if (options.topK >= 0 && hits.length > options.topK) {\n hits.length = options.topK;\n }\n\n return hits;\n }\n\n /**\n * Get lru capacity\n */\n public get capacity() {\n return this.options.capacity || 1000;\n }\n\n /**\n * {@inheritdoc}\n */\n public async disconnect() {\n // Clear the cleanup interval to prevent memory leaks\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval);\n this.cleanupInterval = undefined;\n }\n\n await super.disconnect();\n }\n}\n"],"mappings":";;;;;;;AAkBA,IAAM,YAAN,MAAgB;CAcd,AAAO,YACL,AAAO,KACP,AAAO,OACP,KACA;EAHO;EACA;cAfuB;cACA;EAiB9B,IAAI,OAAO,QAAQ,UACjB,KAAK,YAAY,KAAK,IAAI,IAAI,MAAM;CAExC;CAEA,IAAW,YAAqB;EAC9B,OAAO,KAAK,cAAc,UAAa,KAAK,YAAY,KAAK,IAAI;CACnE;AACF;;;;;;;AAQA,IAAa,uBAAb,cACU,gBAEV;;;;CAkCE,AAAO,cAAc;EACnB,MAAM;cA/BM;+BAK4B,IAAI,IAAI;kBAKX,IAAI,iBAAiB;cAKhC,IAAI,UAAU,IAAI,IAAI;cAKtB,IAAI,UAAU,IAAI,IAAI;EAahD,KAAK,KAAK;EACV,KAAK,aAAa;CACpB;;;;CAKA,AAAO,OAAO;EACZ,KAAK,KAAK,OAAO,KAAK;EACtB,KAAK,KAAK,OAAO,KAAK;CACxB;;;;CAKA,AAAO,eAAe;EAEpB,IAAI,KAAK,iBACP,cAAc,KAAK,eAAe;EAGpC,KAAK,kBAAkB,YAAY,YAAY;GAC7C,MAAM,MAAM,KAAK,IAAI;GACrB,MAAM,cAAwB,CAAC;GAE/B,KAAK,MAAM,CAAC,KAAK,SAAS,KAAK,OAC7B,IAAI,KAAK,aAAa,KAAK,aAAa,KACtC,YAAY,KAAK,GAAG;GAIxB,KAAK,MAAM,OAAO,aAAa;IAC7B,MAAM,OAAO,KAAK,MAAM,IAAI,GAAG;IAC/B,IAAI,MAAM;KACR,KAAK,WAAW,IAAI;KACpB,KAAK,MAAM,OAAO,GAAG;KACrB,KAAK,IAAI,WAAW,GAAG;KAE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AClC;;;;CAKA,MAAa,aAAa;EAExB,IAAI,KAAK,iBAAiB;GACxB,cAAc,KAAK,eAAe;GAClC,KAAK,kBAAkB;EACzB;EAEA,MAAM,MAAM,WAAW;CACzB;AACF"}
|
|
1
|
+
{"version":3,"file":"lru-memory-cache-driver.mjs","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/lru-memory-cache-driver.ts"],"mappings":";;;;;;;;AAoBA,IAAM,YAAN,MAAgB;CAcd,AAAO,YACL,AAAO,KACP,AAAO,OACP,KACA;EAHO;EACA;cAfuB;cACA;EAiB9B,IAAI,OAAO,QAAQ,UACjB,KAAK,YAAY,KAAK,IAAI,IAAI,MAAM;CAExC;CAEA,IAAW,YAAqB;EAC9B,OAAO,KAAK,cAAc,UAAa,KAAK,YAAY,KAAK,IAAI;CACnE;AACF;;;;;;;AAQA,IAAa,uBAAb,cACU,gBAEV;;;;CAkCE,AAAO,cAAc;EACnB,MAAM;cA/BM;+BAK4B,IAAI,IAAI;kBAKX,IAAI,iBAAiB;cAKhC,IAAI,UAAU,IAAI,IAAI;cAKtB,IAAI,UAAU,IAAI,IAAI;EAahD,KAAK,KAAK;EACV,KAAK,aAAa;CACpB;;;;CAKA,AAAO,OAAO;EACZ,KAAK,KAAK,OAAO,KAAK;EACtB,KAAK,KAAK,OAAO,KAAK;CACxB;;;;CAKA,AAAO,eAAe;EAEpB,IAAI,KAAK,iBACP,cAAc,KAAK,eAAe;EAGpC,KAAK,kBAAkB,YAAY,YAAY;GAC7C,MAAM,MAAM,KAAK,IAAI;GACrB,MAAM,cAAwB,CAAC;GAE/B,KAAK,MAAM,CAAC,KAAK,SAAS,KAAK,OAC7B,IAAI,KAAK,aAAa,KAAK,aAAa,KACtC,YAAY,KAAK,GAAG;GAIxB,KAAK,MAAM,OAAO,aAAa;IAC7B,MAAM,OAAO,KAAK,MAAM,IAAI,GAAG;IAC/B,IAAI,MAAM;KACR,KAAK,WAAW,IAAI;KACpB,KAAK,MAAM,OAAO,GAAG;KACr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ACtB,IAAI,UAAU,QAAQ,UAAU,QAAW;IACzC,MAAM,IAAI,OAAO;IACjB,IAAI,MAAM,YAAY,MAAM,YAAY,MAAM,WAC5C,QAAQ,gBAAgB,KAAK;GAEjC;GAEA,KAAK,KAAK;IAAE,KAAK;IAAW;IAAO;GAAM,CAAC;EAC5C;EAEA,KAAK,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;EAErC,IAAI,QAAQ,QAAQ,KAAK,KAAK,SAAS,QAAQ,MAC7C,KAAK,SAAS,QAAQ;EAGxB,OAAO;CACT;;;;CAKA,IAAW,WAAW;EACpB,OAAO,KAAK,QAAQ,YAAY;CAClC;;;;CAKA,MAAa,aAAa;EAExB,IAAI,KAAK,iBAAiB;GACxB,cAAc,KAAK,eAAe;GAClC,KAAK,kBAAkB;EACzB;EAEA,MAAM,MAAM,WAAW;CACzB;AACF"}
|
|
@@ -68,7 +68,12 @@ export declare class MemoryCacheDriver extends BaseCacheDriver<MemoryCacheDriver
|
|
|
68
68
|
*/
|
|
69
69
|
protected readLive(parsedKey: string): CacheData | undefined;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* The entry limit: `maxSize`, or 10,000 when it is not set. `Infinity`
|
|
72
|
+
* (or `0`) means no limit.
|
|
73
|
+
*/
|
|
74
|
+
protected get maxSize(): number;
|
|
75
|
+
/**
|
|
76
|
+
* Mark an entry as most recently used (not tracked without a limit).
|
|
72
77
|
*/
|
|
73
78
|
protected touch(parsedKey: string, entry: CacheData): void;
|
|
74
79
|
/**
|
|
@@ -158,6 +163,16 @@ export declare class MemoryCacheDriver extends BaseCacheDriver<MemoryCacheDriver
|
|
|
158
163
|
* {@inheritdoc}
|
|
159
164
|
*/
|
|
160
165
|
tagDelete(tagKey: CacheKey): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* {@inheritdoc}
|
|
168
|
+
*/
|
|
169
|
+
tagSample(tagKey: CacheKey, count: number): Promise<string[]>;
|
|
170
|
+
/**
|
|
171
|
+
* {@inheritdoc}
|
|
172
|
+
*
|
|
173
|
+
* A synchronous lookup: no copy, no events, no recency or TTL change.
|
|
174
|
+
*/
|
|
175
|
+
exists(key: CacheKey): Promise<boolean>;
|
|
161
176
|
/**
|
|
162
177
|
* {@inheritdoc}
|
|
163
178
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/memory-cache-driver.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"memory-cache-driver.d.mts","names":[],"sources":["../../../../../../../../packages/cache/src/drivers/memory-cache-driver.ts"],"mappings":";;;;;;qBA2Ca,0BACH,gBAAgB,mBAAmB,+BAChC,YAAY,mBAAmB,qBAAqB;;;;EAKxD;;;;;;YAOG,SAAS,YAAY;;;;;MAMpB,QAAQ,eAAe;;;;;YAQxB,QAAQ;;;;YAKR,kBAAkB,OAAO;;;;;;;YAQzB,aAAa;;;;;YAMb,UAAU;;;;EAKpB;;;;EASO;;;;;YAwCG,iBAAiB;;;;EAKpB,qBAAqB;;;;YASlB,UAAU;;;;;YAUV,SAAS,oBAAoB;;;;;gBAmBzB;;;;YAWJ,MAAM,mBAAmB,OAAO;;;;;;;YAahC;;;;;;YAOA,OAAO,mBAAmB,OAAO;;;;EAiB9B,gBAAgB,oBAAiB;;;;;;;EAmCjC,IACX,KAAK,UACL,YACA,eAAe,WAAW,kBACzB;;;;;;;YA8Da,eAAe,KAAK,UAAU,oBAAoB;;;;;;;;EAoBrD,UACX,KAAK,UACL,gBACA;IAAW,MAAM;MAChB;;;;;;;EAgDU,OAAO,KAAK,UAAU,KAAK,WAAW;;;;;;;EA8BtC,KAAK,KAAK,WAAW;;;;EAuBrB,IAAI,KAAK,WAAQ;;;;;;YA8Bd,SAAS,KAAK,WAAW,QAAQ;;;;EAapC,OAAO,KAAK,WAAQ;;;;;;EAkBpB,OAAO,QAAQ,UAAU,oBAAoB;;;;EAO7C,WAAW,QAAQ,WAAW;;;;EAO9B,UAAU,QAAQ,UAAU,oBAAoB;;;;EAOhD,UAAU,QAAQ,WAAW;;;;EAO7B,UAAU,QAAQ,UAAU,gBAAgB;;;;;;EAS5C,OAAO,KAAK,WAAW;;;;EAOvB,SAAK;;;;;YAsBR,eAAe;;;;;;;;;;;EAmCZ,QAAQ,SACnB,kBACA,SAAS,sBACR,QAAQ,gBAAgB;;;;EAyCd,cAAU"}
|
|
@@ -15,6 +15,12 @@ function cloneValue(value) {
|
|
|
15
15
|
if (type === "string" || type === "number" || type === "boolean") return value;
|
|
16
16
|
return structuredClone(value);
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Entries a memory driver keeps when `maxSize` is not configured. Past it the
|
|
20
|
+
* least recently used entries are evicted, so request-derived keys cannot
|
|
21
|
+
* grow the heap without bound.
|
|
22
|
+
*/
|
|
23
|
+
const DEFAULT_MAX_SIZE = 1e4;
|
|
18
24
|
var MemoryCacheDriver = class extends BaseCacheDriver {
|
|
19
25
|
/**
|
|
20
26
|
* Read-only object view of the stored entries, keyed by parsed key.
|
|
@@ -84,10 +90,19 @@ var MemoryCacheDriver = class extends BaseCacheDriver {
|
|
|
84
90
|
return entry;
|
|
85
91
|
}
|
|
86
92
|
/**
|
|
87
|
-
*
|
|
93
|
+
* The entry limit: `maxSize`, or 10,000 when it is not set. `Infinity`
|
|
94
|
+
* (or `0`) means no limit.
|
|
95
|
+
*/
|
|
96
|
+
get maxSize() {
|
|
97
|
+
const configured = this.options?.maxSize;
|
|
98
|
+
if (configured === void 0) return DEFAULT_MAX_SIZE;
|
|
99
|
+
return configured > 0 ? configured : Infinity;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Mark an entry as most recently used (not tracked without a limit).
|
|
88
103
|
*/
|
|
89
104
|
touch(parsedKey, entry) {
|
|
90
|
-
if (
|
|
105
|
+
if (this.maxSize === Infinity) return;
|
|
91
106
|
this.entries.delete(parsedKey);
|
|
92
107
|
this.entries.set(parsedKey, entry);
|
|
93
108
|
}
|
|
@@ -331,6 +346,20 @@ var MemoryCacheDriver = class extends BaseCacheDriver {
|
|
|
331
346
|
/**
|
|
332
347
|
* {@inheritdoc}
|
|
333
348
|
*/
|
|
349
|
+
async tagSample(tagKey, count) {
|
|
350
|
+
return this.tagIndex.sample(this.parseKey(tagKey), count);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* {@inheritdoc}
|
|
354
|
+
*
|
|
355
|
+
* A synchronous lookup: no copy, no events, no recency or TTL change.
|
|
356
|
+
*/
|
|
357
|
+
async exists(key) {
|
|
358
|
+
return this.readLive(this.parseKey(key)) !== void 0;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* {@inheritdoc}
|
|
362
|
+
*/
|
|
334
363
|
async flush() {
|
|
335
364
|
this.log("flushing");
|
|
336
365
|
if (this.options.globalPrefix) await this.removeNamespace("");
|
|
@@ -349,9 +378,9 @@ var MemoryCacheDriver = class extends BaseCacheDriver {
|
|
|
349
378
|
* within `maxSize`. Never evicts `protectedKey` (the key just written).
|
|
350
379
|
*/
|
|
351
380
|
enforceMaxSize(protectedKey) {
|
|
352
|
-
const maxSize = this.
|
|
353
|
-
if (
|
|
354
|
-
for (const lruKey of
|
|
381
|
+
const maxSize = this.maxSize;
|
|
382
|
+
if (this.entries.size <= maxSize) return;
|
|
383
|
+
for (const lruKey of this.entries.keys()) {
|
|
355
384
|
if (this.entries.size <= maxSize) break;
|
|
356
385
|
if (lruKey === protectedKey) continue;
|
|
357
386
|
this.log("removing", lruKey);
|