@warlock.js/cache 4.0.171 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/cjs/index.cjs +4088 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/cache-manager.d.mts +314 -0
- package/esm/cache-manager.d.mts.map +1 -0
- package/esm/cache-manager.mjs +486 -0
- package/esm/cache-manager.mjs.map +1 -0
- package/esm/cached/auto-key.d.mts +25 -0
- package/esm/cached/auto-key.d.mts.map +1 -0
- package/esm/cached/auto-key.mjs +55 -0
- package/esm/cached/auto-key.mjs.map +1 -0
- package/esm/cached/cached.d.mts +54 -0
- package/esm/cached/cached.d.mts.map +1 -0
- package/esm/cached/cached.mjs +25 -0
- package/esm/cached/cached.mjs.map +1 -0
- package/esm/cached/index.d.mts +3 -0
- package/esm/cached/index.mjs +5 -0
- package/esm/cached/normalize-args.d.mts +51 -0
- package/esm/cached/normalize-args.d.mts.map +1 -0
- package/esm/cached/normalize-args.mjs +26 -0
- package/esm/cached/normalize-args.mjs.map +1 -0
- package/esm/drivers/base-cache-driver.d.mts +322 -0
- package/esm/drivers/base-cache-driver.d.mts.map +1 -0
- package/esm/drivers/base-cache-driver.mjs +522 -0
- package/esm/drivers/base-cache-driver.mjs.map +1 -0
- package/esm/drivers/file-cache-driver.d.mts +68 -0
- package/esm/drivers/file-cache-driver.d.mts.map +1 -0
- package/esm/drivers/file-cache-driver.mjs +174 -0
- package/esm/drivers/file-cache-driver.mjs.map +1 -0
- package/esm/drivers/index.d.mts +9 -0
- package/esm/drivers/index.mjs +11 -0
- package/esm/drivers/lru-memory-cache-driver.d.mts +136 -0
- package/esm/drivers/lru-memory-cache-driver.d.mts.map +1 -0
- package/esm/drivers/lru-memory-cache-driver.mjs +317 -0
- package/esm/drivers/lru-memory-cache-driver.mjs.map +1 -0
- package/esm/drivers/memory-cache-driver.d.mts +112 -0
- package/esm/drivers/memory-cache-driver.d.mts.map +1 -0
- package/esm/drivers/memory-cache-driver.mjs +241 -0
- package/esm/drivers/memory-cache-driver.mjs.map +1 -0
- package/esm/drivers/memory-extended-cache-driver.d.mts +17 -0
- package/esm/drivers/memory-extended-cache-driver.d.mts.map +1 -0
- package/esm/drivers/memory-extended-cache-driver.mjs +34 -0
- package/esm/drivers/memory-extended-cache-driver.mjs.map +1 -0
- package/esm/drivers/mock-cache-driver.d.mts +137 -0
- package/esm/drivers/mock-cache-driver.d.mts.map +1 -0
- package/esm/drivers/mock-cache-driver.mjs +226 -0
- package/esm/drivers/mock-cache-driver.mjs.map +1 -0
- package/esm/drivers/null-cache-driver.d.mts +69 -0
- package/esm/drivers/null-cache-driver.d.mts.map +1 -0
- package/esm/drivers/null-cache-driver.mjs +92 -0
- package/esm/drivers/null-cache-driver.mjs.map +1 -0
- package/esm/drivers/pg-cache-driver.d.mts +148 -0
- package/esm/drivers/pg-cache-driver.d.mts.map +1 -0
- package/esm/drivers/pg-cache-driver.mjs +437 -0
- package/esm/drivers/pg-cache-driver.mjs.map +1 -0
- package/esm/drivers/redis-cache-driver.d.mts +86 -0
- package/esm/drivers/redis-cache-driver.d.mts.map +1 -0
- package/esm/drivers/redis-cache-driver.mjs +312 -0
- package/esm/drivers/redis-cache-driver.mjs.map +1 -0
- package/esm/index.d.mts +21 -0
- package/esm/index.mjs +24 -0
- package/esm/list/index.d.mts +1 -0
- package/esm/list/memory-cache-list.d.mts +77 -0
- package/esm/list/memory-cache-list.d.mts.map +1 -0
- package/esm/list/memory-cache-list.mjs +119 -0
- package/esm/list/memory-cache-list.mjs.map +1 -0
- package/esm/metrics.d.mts +118 -0
- package/esm/metrics.d.mts.map +1 -0
- package/esm/metrics.mjs +197 -0
- package/esm/metrics.mjs.map +1 -0
- package/esm/scoped-cache.d.mts +205 -0
- package/esm/scoped-cache.d.mts.map +1 -0
- package/esm/scoped-cache.mjs +274 -0
- package/esm/scoped-cache.mjs.map +1 -0
- package/esm/tagged-cache.d.mts +89 -0
- package/esm/tagged-cache.d.mts.map +1 -0
- package/esm/tagged-cache.mjs +147 -0
- package/esm/tagged-cache.mjs.map +1 -0
- package/esm/tagged-scoped-cache.d.mts +111 -0
- package/esm/tagged-scoped-cache.d.mts.map +1 -0
- package/esm/tagged-scoped-cache.mjs +142 -0
- package/esm/tagged-scoped-cache.mjs.map +1 -0
- package/esm/types.d.mts +1067 -0
- package/esm/types.d.mts.map +1 -0
- package/esm/types.mjs +62 -0
- package/esm/types.mjs.map +1 -0
- package/esm/utils.d.mts +161 -0
- package/esm/utils.d.mts.map +1 -0
- package/esm/utils.mjs +222 -0
- package/esm/utils.mjs.map +1 -0
- package/llms-full.txt +2071 -0
- package/llms.txt +28 -0
- package/package.json +53 -39
- package/skills/apply-cache-patterns/SKILL.md +97 -0
- package/skills/cache-basics/SKILL.md +121 -0
- package/skills/configure-pg-cache/SKILL.md +115 -0
- package/skills/configure-set-options/SKILL.md +96 -0
- package/skills/handle-cache-errors/SKILL.md +91 -0
- package/skills/observe-cache/SKILL.md +103 -0
- package/skills/overview/SKILL.md +69 -0
- package/skills/pick-cache-driver/SKILL.md +115 -0
- package/skills/test-cache-code/SKILL.md +219 -0
- package/skills/use-cache-atomic/SKILL.md +67 -0
- package/skills/use-cache-bulk/SKILL.md +57 -0
- package/skills/use-cache-list/SKILL.md +85 -0
- package/skills/use-cache-lock/SKILL.md +104 -0
- package/skills/use-cache-namespace/SKILL.md +88 -0
- package/skills/use-cache-similarity/SKILL.md +94 -0
- package/skills/use-cache-tags/SKILL.md +85 -0
- package/skills/use-cache-update-merge/SKILL.md +84 -0
- package/skills/use-cache-utils/SKILL.md +89 -0
- package/skills/use-cached-hof/SKILL.md +102 -0
- package/skills/use-swr/SKILL.md +104 -0
- package/cjs/cache-manager.d.ts +0 -163
- package/cjs/cache-manager.d.ts.map +0 -1
- package/cjs/cache-manager.js +0 -322
- package/cjs/cache-manager.js.map +0 -1
- package/cjs/drivers/base-cache-driver.d.ts +0 -152
- package/cjs/drivers/base-cache-driver.d.ts.map +0 -1
- package/cjs/drivers/base-cache-driver.js +0 -321
- package/cjs/drivers/base-cache-driver.js.map +0 -1
- package/cjs/drivers/file-cache-driver.d.ts +0 -45
- package/cjs/drivers/file-cache-driver.d.ts.map +0 -1
- package/cjs/drivers/file-cache-driver.js +0 -133
- package/cjs/drivers/file-cache-driver.js.map +0 -1
- package/cjs/drivers/index.d.ts +0 -8
- package/cjs/drivers/index.d.ts.map +0 -1
- package/cjs/drivers/lru-memory-cache-driver.d.ts +0 -98
- package/cjs/drivers/lru-memory-cache-driver.d.ts.map +0 -1
- package/cjs/drivers/lru-memory-cache-driver.js +0 -252
- package/cjs/drivers/lru-memory-cache-driver.js.map +0 -1
- package/cjs/drivers/memory-cache-driver.d.ts +0 -82
- package/cjs/drivers/memory-cache-driver.d.ts.map +0 -1
- package/cjs/drivers/memory-cache-driver.js +0 -218
- package/cjs/drivers/memory-cache-driver.js.map +0 -1
- package/cjs/drivers/memory-extended-cache-driver.d.ts +0 -13
- package/cjs/drivers/memory-extended-cache-driver.d.ts.map +0 -1
- package/cjs/drivers/memory-extended-cache-driver.js +0 -25
- package/cjs/drivers/memory-extended-cache-driver.js.map +0 -1
- package/cjs/drivers/null-cache-driver.d.ts +0 -58
- package/cjs/drivers/null-cache-driver.d.ts.map +0 -1
- package/cjs/drivers/null-cache-driver.js +0 -84
- package/cjs/drivers/null-cache-driver.js.map +0 -1
- package/cjs/drivers/redis-cache-driver.d.ts +0 -57
- package/cjs/drivers/redis-cache-driver.d.ts.map +0 -1
- package/cjs/drivers/redis-cache-driver.js +0 -263
- package/cjs/drivers/redis-cache-driver.js.map +0 -1
- package/cjs/index.d.ts +0 -6
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/tagged-cache.d.ts +0 -77
- package/cjs/tagged-cache.d.ts.map +0 -1
- package/cjs/tagged-cache.js +0 -160
- package/cjs/tagged-cache.js.map +0 -1
- package/cjs/types.d.ts +0 -391
- package/cjs/types.d.ts.map +0 -1
- package/cjs/types.js +0 -36
- package/cjs/types.js.map +0 -1
- package/cjs/utils.d.ts +0 -50
- package/cjs/utils.d.ts.map +0 -1
- package/cjs/utils.js +0 -55
- package/cjs/utils.js.map +0 -1
- package/esm/cache-manager.d.ts +0 -163
- package/esm/cache-manager.d.ts.map +0 -1
- package/esm/cache-manager.js +0 -322
- package/esm/cache-manager.js.map +0 -1
- package/esm/drivers/base-cache-driver.d.ts +0 -152
- package/esm/drivers/base-cache-driver.d.ts.map +0 -1
- package/esm/drivers/base-cache-driver.js +0 -321
- package/esm/drivers/base-cache-driver.js.map +0 -1
- package/esm/drivers/file-cache-driver.d.ts +0 -45
- package/esm/drivers/file-cache-driver.d.ts.map +0 -1
- package/esm/drivers/file-cache-driver.js +0 -133
- package/esm/drivers/file-cache-driver.js.map +0 -1
- package/esm/drivers/index.d.ts +0 -8
- package/esm/drivers/index.d.ts.map +0 -1
- package/esm/drivers/lru-memory-cache-driver.d.ts +0 -98
- package/esm/drivers/lru-memory-cache-driver.d.ts.map +0 -1
- package/esm/drivers/lru-memory-cache-driver.js +0 -252
- package/esm/drivers/lru-memory-cache-driver.js.map +0 -1
- package/esm/drivers/memory-cache-driver.d.ts +0 -82
- package/esm/drivers/memory-cache-driver.d.ts.map +0 -1
- package/esm/drivers/memory-cache-driver.js +0 -218
- package/esm/drivers/memory-cache-driver.js.map +0 -1
- package/esm/drivers/memory-extended-cache-driver.d.ts +0 -13
- package/esm/drivers/memory-extended-cache-driver.d.ts.map +0 -1
- package/esm/drivers/memory-extended-cache-driver.js +0 -25
- package/esm/drivers/memory-extended-cache-driver.js.map +0 -1
- package/esm/drivers/null-cache-driver.d.ts +0 -58
- package/esm/drivers/null-cache-driver.d.ts.map +0 -1
- package/esm/drivers/null-cache-driver.js +0 -84
- package/esm/drivers/null-cache-driver.js.map +0 -1
- package/esm/drivers/redis-cache-driver.d.ts +0 -57
- package/esm/drivers/redis-cache-driver.d.ts.map +0 -1
- package/esm/drivers/redis-cache-driver.js +0 -263
- package/esm/drivers/redis-cache-driver.js.map +0 -1
- package/esm/index.d.ts +0 -6
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +0 -1
- package/esm/tagged-cache.d.ts +0 -77
- package/esm/tagged-cache.d.ts.map +0 -1
- package/esm/tagged-cache.js +0 -160
- package/esm/tagged-cache.js.map +0 -1
- package/esm/types.d.ts +0 -391
- package/esm/types.d.ts.map +0 -1
- package/esm/types.js +0 -36
- package/esm/types.js.map +0 -1
- package/esm/utils.d.ts +0 -50
- package/esm/utils.d.ts.map +0 -1
- package/esm/utils.js +0 -55
- package/esm/utils.js.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CacheTtl } from "../types.mjs";
|
|
2
|
+
import { CachedOptions } from "./normalize-args.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/cache/src/cached/cached.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The shape returned by `cached()`. Callable like the wrapped function, plus
|
|
7
|
+
* helpers for manual invalidation.
|
|
8
|
+
*/
|
|
9
|
+
type CachedFn<Args extends unknown[], R> = ((...args: Args) => Promise<R>) & {
|
|
10
|
+
/**
|
|
11
|
+
* Drop the cache entry for a specific argument combination.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const getUser = cached((id: number) => db.users.find(id), "user", "1h");
|
|
15
|
+
* await getUser.invalidate(42); // drops "user.42"
|
|
16
|
+
*/
|
|
17
|
+
invalidate(...args: Args): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Wrap an async function so every invocation runs through the cache.
|
|
21
|
+
*
|
|
22
|
+
* Uses `cache.remember()` internally — inherits its stampede-protection
|
|
23
|
+
* guarantees. Three calling shapes, `fn` always first.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Shorthand — prefix auto-expands with the function's arguments.
|
|
27
|
+
* // getUser(42) caches under "user.42".
|
|
28
|
+
* const getUser = cached(
|
|
29
|
+
* (id: number) => db.users.find(id),
|
|
30
|
+
* "user",
|
|
31
|
+
* "1h",
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Options form — custom key function, tags, per-call driver override.
|
|
36
|
+
* const searchProducts = cached(
|
|
37
|
+
* (filters: ProductFilters) => db.products.search(filters),
|
|
38
|
+
* {
|
|
39
|
+
* key: (filters) => `products.search.${filters.category}.${filters.sort}`,
|
|
40
|
+
* ttl: "15m",
|
|
41
|
+
* tags: ["products"],
|
|
42
|
+
* },
|
|
43
|
+
* );
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // Manual invalidation — uses the same key scheme the wrapper uses internally.
|
|
47
|
+
* await getUser.invalidate(42);
|
|
48
|
+
*/
|
|
49
|
+
declare function cached<Args extends unknown[], R>(fn: (...args: Args) => Promise<R>, prefix: string): CachedFn<Args, R>;
|
|
50
|
+
declare function cached<Args extends unknown[], R>(fn: (...args: Args) => Promise<R>, prefix: string, ttl: CacheTtl): CachedFn<Args, R>;
|
|
51
|
+
declare function cached<Args extends unknown[], R>(fn: (...args: Args) => Promise<R>, options: CachedOptions<Args>): CachedFn<Args, R>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { CachedFn, cached };
|
|
54
|
+
//# sourceMappingURL=cached.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached.d.mts","names":[],"sources":["../../../../../../@warlock.js/cache/src/cached/cached.ts"],"mappings":";;;;;;AASA;;KAAY,QAAA,mCAA2C,IAAA,EAAM,IAAA,KAAS,OAAA,CAAQ,CAAA;EAAjB;;;;;;;EAQ3D,UAAA,IAAc,IAAA,EAAM,IAAA,GAAO,OAAA;AAAA;;;;;;;;;;AAAO;AAiCpC;;;;;;;;;;;;;;;;;;;;iBAAgB,MAAA,2BAAA,CACd,EAAA,MAAQ,IAAA,EAAM,IAAA,KAAS,OAAA,CAAQ,CAAA,GAC/B,MAAA,WACC,QAAA,CAAS,IAAA,EAAM,CAAA;AAAA,iBACF,MAAA,2BAAA,CACd,EAAA,MAAQ,IAAA,EAAM,IAAA,KAAS,OAAA,CAAQ,CAAA,GAC/B,MAAA,UACA,GAAA,EAAK,QAAA,GACJ,QAAA,CAAS,IAAA,EAAM,CAAA;AAAA,iBACF,MAAA,2BAAA,CACd,EAAA,MAAQ,IAAA,EAAM,IAAA,KAAS,OAAA,CAAQ,CAAA,GAC/B,OAAA,EAAS,aAAA,CAAc,IAAA,IACtB,QAAA,CAAS,IAAA,EAAM,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { cache } from "../cache-manager.mjs";
|
|
2
|
+
import { normalizeCachedArgs } from "./normalize-args.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/cache/src/cached/cached.ts
|
|
5
|
+
function cached(fn, prefixOrOptions, maybeTtl) {
|
|
6
|
+
const config = normalizeCachedArgs(prefixOrOptions, maybeTtl);
|
|
7
|
+
const buildRememberOptions = () => ({
|
|
8
|
+
ttl: config.ttl,
|
|
9
|
+
tags: config.tags,
|
|
10
|
+
driver: config.driver
|
|
11
|
+
});
|
|
12
|
+
const wrapper = (async (...args) => {
|
|
13
|
+
const key = config.key(...args);
|
|
14
|
+
return cache.remember(key, buildRememberOptions(), () => fn(...args));
|
|
15
|
+
});
|
|
16
|
+
wrapper.invalidate = async (...args) => {
|
|
17
|
+
const key = config.key(...args);
|
|
18
|
+
await cache.remove(key);
|
|
19
|
+
};
|
|
20
|
+
return wrapper;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { cached };
|
|
25
|
+
//# sourceMappingURL=cached.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached.mjs","names":[],"sources":["../../../../../../@warlock.js/cache/src/cached/cached.ts"],"sourcesContent":["import { cache } from \"../cache-manager\";\nimport type { CacheTtl, RememberOptions } from \"../types\";\nimport type { CachedOptions } from \"./normalize-args\";\nimport { normalizeCachedArgs } from \"./normalize-args\";\n\n/**\n * The shape returned by `cached()`. Callable like the wrapped function, plus\n * helpers for manual invalidation.\n */\nexport type CachedFn<Args extends unknown[], R> = ((...args: Args) => Promise<R>) & {\n /**\n * Drop the cache entry for a specific argument combination.\n *\n * @example\n * const getUser = cached((id: number) => db.users.find(id), \"user\", \"1h\");\n * await getUser.invalidate(42); // drops \"user.42\"\n */\n invalidate(...args: Args): Promise<void>;\n};\n\n/**\n * Wrap an async function so every invocation runs through the cache.\n *\n * Uses `cache.remember()` internally — inherits its stampede-protection\n * guarantees. Three calling shapes, `fn` always first.\n *\n * @example\n * // Shorthand — prefix auto-expands with the function's arguments.\n * // getUser(42) caches under \"user.42\".\n * const getUser = cached(\n * (id: number) => db.users.find(id),\n * \"user\",\n * \"1h\",\n * );\n *\n * @example\n * // Options form — custom key function, tags, per-call driver override.\n * const searchProducts = cached(\n * (filters: ProductFilters) => db.products.search(filters),\n * {\n * key: (filters) => `products.search.${filters.category}.${filters.sort}`,\n * ttl: \"15m\",\n * tags: [\"products\"],\n * },\n * );\n *\n * @example\n * // Manual invalidation — uses the same key scheme the wrapper uses internally.\n * await getUser.invalidate(42);\n */\nexport function cached<Args extends unknown[], R>(\n fn: (...args: Args) => Promise<R>,\n prefix: string,\n): CachedFn<Args, R>;\nexport function cached<Args extends unknown[], R>(\n fn: (...args: Args) => Promise<R>,\n prefix: string,\n ttl: CacheTtl,\n): CachedFn<Args, R>;\nexport function cached<Args extends unknown[], R>(\n fn: (...args: Args) => Promise<R>,\n options: CachedOptions<Args>,\n): CachedFn<Args, R>;\nexport function cached<Args extends unknown[], R>(\n fn: (...args: Args) => Promise<R>,\n prefixOrOptions: string | CachedOptions<Args>,\n maybeTtl?: CacheTtl,\n): CachedFn<Args, R> {\n const config = normalizeCachedArgs<Args>(prefixOrOptions, maybeTtl);\n\n // Build the RememberOptions payload once per call. `ttl` may still be undefined\n // here — that's fine, `remember` falls back to the driver's default TTL.\n const buildRememberOptions = (): RememberOptions => ({\n ttl: config.ttl,\n tags: config.tags,\n driver: config.driver,\n });\n\n const wrapper = (async (...args: Args): Promise<R> => {\n const key = config.key(...args);\n return cache.remember<R>(key, buildRememberOptions(), () => fn(...args));\n }) as CachedFn<Args, R>;\n\n wrapper.invalidate = async (...args: Args): Promise<void> => {\n const key = config.key(...args);\n await cache.remove(key);\n };\n\n return wrapper;\n}\n"],"mappings":";;;;AA+DA,SAAgB,OACd,IACA,iBACA,UACmB;CACnB,MAAM,SAAS,oBAA0B,iBAAiB,QAAQ;CAIlE,MAAM,8BAA+C;EACnD,KAAK,OAAO;EACZ,MAAM,OAAO;EACb,QAAQ,OAAO;CACjB;CAEA,MAAM,WAAW,OAAO,GAAG,SAA2B;EACpD,MAAM,MAAM,OAAO,IAAI,GAAG,IAAI;EAC9B,OAAO,MAAM,SAAY,KAAK,qBAAqB,SAAS,GAAG,GAAG,IAAI,CAAC;CACzE;CAEA,QAAQ,aAAa,OAAO,GAAG,SAA8B;EAC3D,MAAM,MAAM,OAAO,IAAI,GAAG,IAAI;EAC9B,MAAM,MAAM,OAAO,GAAG;CACxB;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CacheTtl } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/cache/src/cached/normalize-args.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Options accepted by the `cached()` factory in its verbose form. `key` is the
|
|
6
|
+
* decisive escape hatch when the shorthand's auto-key rules don't fit.
|
|
7
|
+
*
|
|
8
|
+
* @see cached
|
|
9
|
+
*/
|
|
10
|
+
type CachedOptions<Args extends unknown[]> = {
|
|
11
|
+
/**
|
|
12
|
+
* Derive a cache key from the wrapped function's arguments. Must be pure and
|
|
13
|
+
* deterministic — every call with equivalent inputs should produce the same
|
|
14
|
+
* key.
|
|
15
|
+
*/
|
|
16
|
+
key: (...args: Args) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Optional TTL on cache miss. Falls back to the driver's default TTL when omitted.
|
|
19
|
+
*/
|
|
20
|
+
ttl?: CacheTtl;
|
|
21
|
+
/**
|
|
22
|
+
* Optional tags attached to every cache-miss write this wrapper produces.
|
|
23
|
+
* Invalidate them the usual way via `cache.tags([...]).invalidate()`.
|
|
24
|
+
*/
|
|
25
|
+
tags?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Per-call driver override. Routes every call produced by this wrapper to
|
|
28
|
+
* the named driver without mutating `currentDriver`.
|
|
29
|
+
*/
|
|
30
|
+
driver?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Normalized form of the factory arguments — a single shape every call path
|
|
34
|
+
* in `cached()` operates on. Users never see this type.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
type NormalizedCachedConfig<Args extends unknown[]> = {
|
|
39
|
+
key: (...args: Args) => string;
|
|
40
|
+
ttl?: CacheTtl;
|
|
41
|
+
tags?: string[];
|
|
42
|
+
driver?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Resolve the positional-or-options arguments of `cached()` into a single
|
|
46
|
+
* normalized config. Keeps the wrapper body free of shape-checks.
|
|
47
|
+
*/
|
|
48
|
+
declare function normalizeCachedArgs<Args extends unknown[]>(prefixOrOptions: string | CachedOptions<Args>, maybeTtl?: CacheTtl): NormalizedCachedConfig<Args>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { CachedOptions, NormalizedCachedConfig, normalizeCachedArgs };
|
|
51
|
+
//# sourceMappingURL=normalize-args.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-args.d.mts","names":[],"sources":["../../../../../../@warlock.js/cache/src/cached/normalize-args.ts"],"mappings":";;;;;AASA;;;;KAAY,aAAA;EAMV;;;;;EAAA,GAAA,MAAS,IAAA,EAAM,IAAA;EAcf;;AAAM;EAVN,GAAA,GAAM,QAAQ;EAmBkB;;;;EAdhC,IAAA;EAeS;;;;EAVT,MAAA;AAAA;;AAaM;AAOR;;;;KAXY,sBAAA;EACV,GAAA,MAAS,IAAA,EAAM,IAAA;EACf,GAAA,GAAM,QAAQ;EACd,IAAA;EACA,MAAA;AAAA;;;;;iBAOc,mBAAA,wBAAA,CACd,eAAA,WAA0B,aAAA,CAAc,IAAA,GACxC,QAAA,GAAW,QAAA,GACV,sBAAA,CAAuB,IAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { deriveAutoKey } from "./auto-key.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/cache/src/cached/normalize-args.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the positional-or-options arguments of `cached()` into a single
|
|
6
|
+
* normalized config. Keeps the wrapper body free of shape-checks.
|
|
7
|
+
*/
|
|
8
|
+
function normalizeCachedArgs(prefixOrOptions, maybeTtl) {
|
|
9
|
+
if (typeof prefixOrOptions === "string") {
|
|
10
|
+
const prefix = prefixOrOptions;
|
|
11
|
+
return {
|
|
12
|
+
key: (...args) => deriveAutoKey(prefix, args),
|
|
13
|
+
ttl: maybeTtl
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
key: prefixOrOptions.key,
|
|
18
|
+
ttl: prefixOrOptions.ttl,
|
|
19
|
+
tags: prefixOrOptions.tags,
|
|
20
|
+
driver: prefixOrOptions.driver
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { normalizeCachedArgs };
|
|
26
|
+
//# sourceMappingURL=normalize-args.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-args.mjs","names":[],"sources":["../../../../../../@warlock.js/cache/src/cached/normalize-args.ts"],"sourcesContent":["import type { CacheTtl } from \"../types\";\nimport { deriveAutoKey } from \"./auto-key\";\n\n/**\n * Options accepted by the `cached()` factory in its verbose form. `key` is the\n * decisive escape hatch when the shorthand's auto-key rules don't fit.\n *\n * @see cached\n */\nexport type CachedOptions<Args extends unknown[]> = {\n /**\n * Derive a cache key from the wrapped function's arguments. Must be pure and\n * deterministic — every call with equivalent inputs should produce the same\n * key.\n */\n key: (...args: Args) => string;\n /**\n * Optional TTL on cache miss. Falls back to the driver's default TTL when omitted.\n */\n ttl?: CacheTtl;\n /**\n * Optional tags attached to every cache-miss write this wrapper produces.\n * Invalidate them the usual way via `cache.tags([...]).invalidate()`.\n */\n tags?: string[];\n /**\n * Per-call driver override. Routes every call produced by this wrapper to\n * the named driver without mutating `currentDriver`.\n */\n driver?: string;\n};\n\n/**\n * Normalized form of the factory arguments — a single shape every call path\n * in `cached()` operates on. Users never see this type.\n *\n * @internal\n */\nexport type NormalizedCachedConfig<Args extends unknown[]> = {\n key: (...args: Args) => string;\n ttl?: CacheTtl;\n tags?: string[];\n driver?: string;\n};\n\n/**\n * Resolve the positional-or-options arguments of `cached()` into a single\n * normalized config. Keeps the wrapper body free of shape-checks.\n */\nexport function normalizeCachedArgs<Args extends unknown[]>(\n prefixOrOptions: string | CachedOptions<Args>,\n maybeTtl?: CacheTtl,\n): NormalizedCachedConfig<Args> {\n if (typeof prefixOrOptions === \"string\") {\n const prefix = prefixOrOptions;\n return {\n key: (...args: Args) => deriveAutoKey(prefix, args),\n ttl: maybeTtl,\n };\n }\n\n return {\n key: prefixOrOptions.key,\n ttl: prefixOrOptions.ttl,\n tags: prefixOrOptions.tags,\n driver: prefixOrOptions.driver,\n };\n}\n"],"mappings":";;;;;;;AAiDA,SAAgB,oBACd,iBACA,UAC8B;CAC9B,IAAI,OAAO,oBAAoB,UAAU;EACvC,MAAM,SAAS;EACf,OAAO;GACL,MAAM,GAAG,SAAe,cAAc,QAAQ,IAAI;GAClD,KAAK;EACP;CACF;CAEA,OAAO;EACL,KAAK,gBAAgB;EACrB,KAAK,gBAAgB;EACrB,MAAM,gBAAgB;EACtB,QAAQ,gBAAgB;CAC1B;AACF"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { CacheConflictPolicy, CacheData, CacheDriver, CacheEventData, CacheEventHandler, CacheEventType, CacheKey, CacheListAccessor, CacheOperationType, CacheSetOptions, CacheSimilarHit, CacheSimilarOptions, CacheSwrOptions, CacheTtl, LockOptions, LockOutcome, RememberOptions } from "../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/cache/src/drivers/base-cache-driver.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Normalized form of the 3rd `set` argument.
|
|
6
|
+
*
|
|
7
|
+
* All drivers operate on this shape internally regardless of whether the caller
|
|
8
|
+
* passed a positional TTL, a duration string, or a rich options object.
|
|
9
|
+
*/
|
|
10
|
+
type NormalizedSetOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* Final TTL in seconds — already merged with the driver-level default
|
|
13
|
+
* (`this.options.ttl`). `Infinity` means "no expiration".
|
|
14
|
+
*
|
|
15
|
+
* Always populated. Drivers do NOT need to fall back to `this.ttl`
|
|
16
|
+
* themselves — `resolveSetOptions` does the merge centrally so that
|
|
17
|
+
* every driver respects the configured default without ceremony.
|
|
18
|
+
*/
|
|
19
|
+
ttl: number;
|
|
20
|
+
/**
|
|
21
|
+
* Inline tag list, or undefined when none were provided.
|
|
22
|
+
*/
|
|
23
|
+
tags?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Conflict policy. Defaults to `"upsert"`.
|
|
26
|
+
*/
|
|
27
|
+
onConflict: CacheConflictPolicy;
|
|
28
|
+
/**
|
|
29
|
+
* Optional embedding vector for similarity retrieval. Drivers that do not
|
|
30
|
+
* support similarity must throw {@link CacheUnsupportedError} when this is
|
|
31
|
+
* present (rather than silently dropping it).
|
|
32
|
+
*/
|
|
33
|
+
vector?: number[];
|
|
34
|
+
/**
|
|
35
|
+
* Optional freshness deadline as a millisecond timestamp. Set by `swr()`
|
|
36
|
+
* to mark when the entry stops being "fresh" and becomes
|
|
37
|
+
* "stale-but-revalidatable." Drivers route this through
|
|
38
|
+
* `prepareDataForStorage` so it persists in the wrapper.
|
|
39
|
+
*/
|
|
40
|
+
staleAt?: number;
|
|
41
|
+
};
|
|
42
|
+
declare abstract class BaseCacheDriver<ClientType, Options extends Record<string, any>> implements CacheDriver<ClientType, Options> {
|
|
43
|
+
/**
|
|
44
|
+
* CLient driver
|
|
45
|
+
*/
|
|
46
|
+
protected clientDriver: ClientType;
|
|
47
|
+
/**
|
|
48
|
+
* Determine whether to log or not
|
|
49
|
+
*/
|
|
50
|
+
protected shouldLog: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* {@inheritdoc}
|
|
53
|
+
*/
|
|
54
|
+
get client(): ClientType;
|
|
55
|
+
/**
|
|
56
|
+
* Set logging state
|
|
57
|
+
*/
|
|
58
|
+
setLoggingState(shouldLog: boolean): this;
|
|
59
|
+
/**
|
|
60
|
+
* Set client driver
|
|
61
|
+
*/
|
|
62
|
+
set client(client: ClientType);
|
|
63
|
+
/**
|
|
64
|
+
* Get the cache driver name
|
|
65
|
+
*/
|
|
66
|
+
abstract name: string;
|
|
67
|
+
/**
|
|
68
|
+
* Options list
|
|
69
|
+
*/
|
|
70
|
+
options: Options;
|
|
71
|
+
/**
|
|
72
|
+
* Event listeners storage
|
|
73
|
+
*/
|
|
74
|
+
protected eventListeners: Map<CacheEventType, Set<CacheEventHandler>>;
|
|
75
|
+
/**
|
|
76
|
+
* {@inheritdoc}
|
|
77
|
+
*/
|
|
78
|
+
parseKey(key: CacheKey): string;
|
|
79
|
+
/**
|
|
80
|
+
* {@inheritdoc}
|
|
81
|
+
*/
|
|
82
|
+
setOptions(options: Options): this;
|
|
83
|
+
/**
|
|
84
|
+
* Register an event listener
|
|
85
|
+
*/
|
|
86
|
+
on(event: CacheEventType, handler: CacheEventHandler): this;
|
|
87
|
+
/**
|
|
88
|
+
* Remove an event listener
|
|
89
|
+
*/
|
|
90
|
+
off(event: CacheEventType, handler: CacheEventHandler): this;
|
|
91
|
+
/**
|
|
92
|
+
* Register a one-time event listener
|
|
93
|
+
*/
|
|
94
|
+
once(event: CacheEventType, handler: CacheEventHandler): this;
|
|
95
|
+
/**
|
|
96
|
+
* Emit an event to all registered listeners
|
|
97
|
+
*/
|
|
98
|
+
protected emit(event: CacheEventType, data?: Partial<CacheEventData>): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* {@inheritdoc}
|
|
101
|
+
*/
|
|
102
|
+
abstract removeNamespace(namespace: string): Promise<any>;
|
|
103
|
+
/**
|
|
104
|
+
* {@inheritdoc}
|
|
105
|
+
*/
|
|
106
|
+
abstract set(key: CacheKey, value: any, ttlOrOptions?: CacheTtl | CacheSetOptions): Promise<any>;
|
|
107
|
+
/**
|
|
108
|
+
* Normalize the 3rd argument of a `set` call into a single shape every driver
|
|
109
|
+
* can act on. Handles TTL parsing (number | string | Infinity), `expiresAt` →
|
|
110
|
+
* relative TTL conversion, and mutual-exclusion validation.
|
|
111
|
+
*
|
|
112
|
+
* @throws {CacheConfigurationError} when `ttl` and `expiresAt` are passed together
|
|
113
|
+
* or an unparseable duration string is supplied.
|
|
114
|
+
*/
|
|
115
|
+
protected resolveSetOptions(ttlOrOptions?: CacheTtl | CacheSetOptions): NormalizedSetOptions;
|
|
116
|
+
/**
|
|
117
|
+
* Resolve the union of cache keys associated with any of the given tags.
|
|
118
|
+
* Used by `similar()` to narrow the candidate pool before similarity ranking.
|
|
119
|
+
*
|
|
120
|
+
* Returns `null` when no tags are passed (callers should treat that as "no filter").
|
|
121
|
+
*/
|
|
122
|
+
protected getKeysForTags(tags: string[] | undefined): Promise<Set<string> | null>;
|
|
123
|
+
/**
|
|
124
|
+
* Apply tag relationships after a successful write. Called by drivers once
|
|
125
|
+
* the value is in storage.
|
|
126
|
+
*/
|
|
127
|
+
protected applyTags(parsedKey: string, tags: string[]): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* {@inheritdoc}
|
|
130
|
+
*/
|
|
131
|
+
abstract get(key: CacheKey): Promise<any>;
|
|
132
|
+
/**
|
|
133
|
+
* {@inheritdoc}
|
|
134
|
+
*/
|
|
135
|
+
abstract remove(key: CacheKey): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* {@inheritdoc}
|
|
138
|
+
*/
|
|
139
|
+
abstract flush(): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* {@inheritdoc}
|
|
142
|
+
*/
|
|
143
|
+
has(key: CacheKey): Promise<boolean>;
|
|
144
|
+
/**
|
|
145
|
+
* Lock storage for preventing cache stampede
|
|
146
|
+
*/
|
|
147
|
+
protected locks: Map<string, Promise<any>>;
|
|
148
|
+
/**
|
|
149
|
+
* {@inheritdoc}
|
|
150
|
+
*/
|
|
151
|
+
remember(key: CacheKey, ttlOrOptions: CacheTtl | RememberOptions, callback: () => Promise<any>): Promise<any>;
|
|
152
|
+
/**
|
|
153
|
+
* Resolve the TTL-or-options arg of `remember` into a `CacheSetOptions` object
|
|
154
|
+
* that can be passed straight to `set()`. Keeps the implementation unbranched.
|
|
155
|
+
*/
|
|
156
|
+
protected normalizeRememberOptions(ttlOrOptions: CacheTtl | RememberOptions): CacheSetOptions;
|
|
157
|
+
/**
|
|
158
|
+
* {@inheritdoc}
|
|
159
|
+
*
|
|
160
|
+
* Default implementation: read raw entry, branch on freshness/staleness,
|
|
161
|
+
* trigger background refresh in the stale window, fall through to
|
|
162
|
+
* `callback` on miss/expiry. Concurrent stale-window callers share a
|
|
163
|
+
* single in-flight refresh via {@link locks}.
|
|
164
|
+
*
|
|
165
|
+
* Drivers without a real {@link getEntry} override degrade gracefully —
|
|
166
|
+
* the synthetic entry has no `staleAt`, which the freshness check treats
|
|
167
|
+
* as "always fresh," so SWR behaves like a TTL-only cached read on those
|
|
168
|
+
* drivers (no background refresh, but no double-fetch either).
|
|
169
|
+
*/
|
|
170
|
+
swr<T = any>(key: CacheKey, options: CacheSwrOptions, callback: () => Promise<T>): Promise<T>;
|
|
171
|
+
/**
|
|
172
|
+
* Read the raw {@link CacheData} wrapper for a key, including any
|
|
173
|
+
* `expiresAt` / `staleAt` metadata. Default implementation falls back to
|
|
174
|
+
* `get()` and synthesizes a metadata-less wrapper — drivers that store
|
|
175
|
+
* the wrapper directly (memory, lru, file, redis, pg, mock) override
|
|
176
|
+
* this to return real metadata so SWR can branch on freshness.
|
|
177
|
+
*/
|
|
178
|
+
protected getEntry(key: CacheKey): Promise<CacheData | null>;
|
|
179
|
+
/**
|
|
180
|
+
* Remaining lifetime of an existing entry, in seconds — used by TTL-preserving
|
|
181
|
+
* writes such as `update()` / `merge()` when the caller passes no explicit
|
|
182
|
+
* `ttl`.
|
|
183
|
+
*
|
|
184
|
+
* - `Infinity` — the entry exists with no expiry (preserve "never expires").
|
|
185
|
+
* - positive number — seconds left before the entry expires.
|
|
186
|
+
* - `undefined` — the key is missing or already past its deadline; the caller
|
|
187
|
+
* should fall back to the driver default TTL.
|
|
188
|
+
*
|
|
189
|
+
* Default reads `expiresAt` from {@link getEntry}, which the metadata-aware
|
|
190
|
+
* drivers (memory, lru, mock, pg) populate. Drivers that track TTL natively
|
|
191
|
+
* and don't carry `expiresAt` in their payload (Redis) override this.
|
|
192
|
+
*/
|
|
193
|
+
protected getRemainingTtl(key: CacheKey): Promise<number | undefined>;
|
|
194
|
+
/**
|
|
195
|
+
* Block-and-fetch path of `swr()`: invoked on miss or past-`staleTtl`
|
|
196
|
+
* expiry. Writes through `set()` with the SWR options translated into
|
|
197
|
+
* standard `CacheSetOptions` (ttl = staleTtl, staleAt = now + freshTtl).
|
|
198
|
+
*/
|
|
199
|
+
protected swrFetchAndStore<T>(key: CacheKey, options: CacheSwrOptions, callback: () => Promise<T>, freshSeconds: number, staleSeconds: number): Promise<T>;
|
|
200
|
+
/**
|
|
201
|
+
* Stale-window background refresh. Registers a single in-flight promise
|
|
202
|
+
* per parsed key so concurrent SWR callers share one refresh. Failed
|
|
203
|
+
* refreshes preserve the stale entry, log via `logError`, and emit on
|
|
204
|
+
* `error` — the stale-returning caller never sees the failure.
|
|
205
|
+
*/
|
|
206
|
+
protected scheduleSwrRefresh<T>(parsedKey: string, key: CacheKey, options: CacheSwrOptions, callback: () => Promise<T>, freshSeconds: number, staleSeconds: number): void;
|
|
207
|
+
/**
|
|
208
|
+
* {@inheritdoc}
|
|
209
|
+
*/
|
|
210
|
+
pull(key: CacheKey): Promise<any | null>;
|
|
211
|
+
/**
|
|
212
|
+
* {@inheritdoc}
|
|
213
|
+
*/
|
|
214
|
+
forever(key: CacheKey, value: any): Promise<any>;
|
|
215
|
+
/**
|
|
216
|
+
* {@inheritdoc}
|
|
217
|
+
*/
|
|
218
|
+
increment(key: CacheKey, value?: number): Promise<number>;
|
|
219
|
+
/**
|
|
220
|
+
* {@inheritdoc}
|
|
221
|
+
*/
|
|
222
|
+
decrement(key: CacheKey, value?: number): Promise<number>;
|
|
223
|
+
/**
|
|
224
|
+
* {@inheritdoc}
|
|
225
|
+
*/
|
|
226
|
+
many(keys: CacheKey[]): Promise<any[]>;
|
|
227
|
+
/**
|
|
228
|
+
* {@inheritdoc}
|
|
229
|
+
*/
|
|
230
|
+
setMany(items: Record<string, any>, ttl?: number): Promise<void>;
|
|
231
|
+
/**
|
|
232
|
+
* Log the operation
|
|
233
|
+
*/
|
|
234
|
+
protected log(operation: CacheOperationType, key?: string): Promise<import("@warlock.js/logger").Logger> | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* Log error message
|
|
237
|
+
*/
|
|
238
|
+
protected logError(message: string, error?: any): void;
|
|
239
|
+
/**
|
|
240
|
+
* Get the default TTL in seconds. Parses human-readable strings (`"1h"`, `"30m"`)
|
|
241
|
+
* from driver options if present; falls back to `Infinity` when no default is set.
|
|
242
|
+
*/
|
|
243
|
+
get ttl(): number;
|
|
244
|
+
/**
|
|
245
|
+
* Get time to live value in milliseconds
|
|
246
|
+
*/
|
|
247
|
+
getExpiresAt(ttl?: number): number | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* Wrap a value with TTL and optional freshness metadata for backend
|
|
250
|
+
* storage. `staleAt` persists alongside `expiresAt` when supplied — used
|
|
251
|
+
* by the SWR flow to mark when the entry stops being fresh.
|
|
252
|
+
*/
|
|
253
|
+
protected prepareDataForStorage(data: any, ttl?: number, staleAt?: number): CacheData;
|
|
254
|
+
/**
|
|
255
|
+
* Parse fetched data from cache
|
|
256
|
+
*/
|
|
257
|
+
protected parseCachedData(key: string, data: CacheData): Promise<any>;
|
|
258
|
+
/**
|
|
259
|
+
* {@inheritdoc}
|
|
260
|
+
*/
|
|
261
|
+
connect(): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* {@inheritdoc}
|
|
264
|
+
*/
|
|
265
|
+
disconnect(): Promise<void>;
|
|
266
|
+
/**
|
|
267
|
+
* Create a tagged cache instance for the given tags
|
|
268
|
+
*/
|
|
269
|
+
tags(tags: string[]): any;
|
|
270
|
+
/**
|
|
271
|
+
* {@inheritdoc}
|
|
272
|
+
*
|
|
273
|
+
* Default implementation: read → transform → write under a per-key in-process
|
|
274
|
+
* lock. Drivers that can offer stronger semantics (Redis via `WATCH`/`MULTI`)
|
|
275
|
+
* should override.
|
|
276
|
+
*/
|
|
277
|
+
update<T = any>(key: CacheKey, fn: (current: T | null) => T | null | Promise<T | null>, options?: {
|
|
278
|
+
ttl?: CacheTtl;
|
|
279
|
+
}): Promise<T | null>;
|
|
280
|
+
/**
|
|
281
|
+
* {@inheritdoc}
|
|
282
|
+
*/
|
|
283
|
+
merge<T extends Record<string, any> = Record<string, any>>(key: CacheKey, partial: Partial<T>, options?: {
|
|
284
|
+
ttl?: CacheTtl;
|
|
285
|
+
}): Promise<T>;
|
|
286
|
+
/**
|
|
287
|
+
* {@inheritdoc}
|
|
288
|
+
*
|
|
289
|
+
* Default implementation: read-mutate-write array backed by the underlying
|
|
290
|
+
* cache entry. Concrete drivers (e.g. Redis) override with native commands.
|
|
291
|
+
*/
|
|
292
|
+
list<T = any>(key: CacheKey): CacheListAccessor<T>;
|
|
293
|
+
/**
|
|
294
|
+
* {@inheritdoc}
|
|
295
|
+
*
|
|
296
|
+
* Built on top of `set({ onConflict: "create" })` — Redis-native `SET … NX EX`
|
|
297
|
+
* under the hood on Redis, emulated via key-existence check on other drivers.
|
|
298
|
+
* The lock value is the resolved `owner` (defaults to `pid.<process.pid>`).
|
|
299
|
+
*
|
|
300
|
+
* Always releases in `finally`, even if `fn` throws — the thrown error
|
|
301
|
+
* propagates to the caller unchanged.
|
|
302
|
+
*/
|
|
303
|
+
lock<T>(key: CacheKey, ttlOrOptions: CacheTtl | Omit<LockOptions, "driver">, fn: () => Promise<T>): Promise<LockOutcome<T>>;
|
|
304
|
+
/**
|
|
305
|
+
* {@inheritdoc}
|
|
306
|
+
*
|
|
307
|
+
* Default implementation throws {@link CacheUnsupportedError}. Drivers that
|
|
308
|
+
* support similarity retrieval (memory family, `pg`, `redis` w/ RediSearch)
|
|
309
|
+
* override this with a real impl.
|
|
310
|
+
*/
|
|
311
|
+
similar<T = any>(_vector: number[], _options: CacheSimilarOptions): Promise<CacheSimilarHit<T>[]>;
|
|
312
|
+
/**
|
|
313
|
+
* Resolve the TTL-or-options arg of `lock` into a uniform shape.
|
|
314
|
+
*/
|
|
315
|
+
protected normalizeLockOptions(ttlOrOptions: CacheTtl | Omit<LockOptions, "driver">): {
|
|
316
|
+
ttl: CacheTtl;
|
|
317
|
+
owner?: string;
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
//#endregion
|
|
321
|
+
export { BaseCacheDriver, NormalizedSetOptions };
|
|
322
|
+
//# sourceMappingURL=base-cache-driver.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-cache-driver.d.mts","names":[],"sources":["../../../../../../@warlock.js/cache/src/drivers/base-cache-driver.ts"],"mappings":";;;;;AAgCA;;;;KAAY,oBAAA;EAaV;;;;;;AAiBO;AAuBT;EA5CE,GAAA;EA4CmC;;;EAxCnC,IAAA;EA+CyB;;;EA3CzB,UAAA,EAAY,mBAAmB;EAsFD;;;;;EAhF9B,MAAA;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