@@ -13,50 +13,44 @@ function cacheAvailable(): boolean {
1313 return ! import . meta. dev && Boolean ( process . env . VERCEL )
1414}
1515
16+ /** Every namespace below degrades to per-process memory off Vercel if not available. */
17+ function runtimeCacheDriver ( base : string , ttl : number ) : Driver {
18+ if ( ! cacheAvailable ( ) ) return memoryDriver ( )
19+ return vercelRuntimeCache ( { base, ttl } )
20+ }
21+
1622/**
1723 * Bump when content parser/plugin configuration, relevant parser dependencies, or cached derived
1824 * data changes. Keeping this explicit lets unrelated deployments reuse immutable content artifacts.
1925 */
2026export const CONTENT_PARSER_VERSION = 'v3'
2127
2228/**
23- * The driver behind everything cached per parser version, under `content:<version>`:
24- *
25- * - without `sha`, comark's index, parsed bodies and artifacts for every commit. An instance pinned
26- * with `content.withRef(sha)` adds its own `ref:<sha>:` prefix, so instances pinned to different
27- * commits share this driver without reading each other's entries;
28- * - with `sha`, ad-hoc per-commit data (commit history, RSS dates) under `content:<version>:<sha>`.
29- * Those keys start with `gh:` and never meet comark's.
30- *
31- * Bumping the parser version leaves every commit's entries behind at once.
29+ * Comark cache: index, parsed bodies and artifacts of every commit.
30+ * Sharing content across all perser versions BUT keys are per-sha.
3231 */
33- export function contentCacheDriver ( sha ?: string ) : Driver {
34- if ( ! cacheAvailable ( ) ) return memoryDriver ( )
35- return vercelRuntimeCache ( {
36- base : sha ? `content:${ CONTENT_PARSER_VERSION } :${ sha } ` : `content:${ CONTENT_PARSER_VERSION } ` ,
37- ttl : TTL ,
38- } )
39- }
40-
41- /** Ad-hoc per-SHA storage for non-content data (commit history, RSS dates). */
42- export function shaCacheStorage ( sha : string ) : Storage {
43- return createStorage ( { driver : contentCacheDriver ( sha ) } )
32+ export function contentCacheDriver ( ) : Driver {
33+ return runtimeCacheDriver ( `content:${ CONTENT_PARSER_VERSION } ` , TTL )
4434}
4535
4636/**
4737 * Shared driver backing the branch + content directory → content commit pointer
4838 * (`resolveContentSha` in `github.ts`), in its own namespace so every instance reads one pointer
4939 * instead of keeping its own timer.
5040 *
51- * Vercel Runtime Cache is **regional**, not global (https://vercel.com/docs/caching/runtime-cache):
52- * this assumes Functions run in a single region (no `regions` in `vercel.json`/`nuxt.config.ts`) .
53- * Multi-region would confine the webhook's forced refresh to its region — others self-heal on TTL,
54- * so reach for a globally replicated store (e.g. Edge Config) only if that day comes .
41+ * TODO: Vercel Runtime Cache is **regional**, not global (https://vercel.com/docs/caching/runtime-cache):
42+ * It assumes Functions run in a single region.
43+ * Multi-region would confine the webhook's forced refresh to its region ( others self-heal on TTL)
44+ * We should reach for a globally replicated store (e.g. Edge Config).
5545 */
5646export function refCacheDriver ( ) : Driver {
57- if ( ! cacheAvailable ( ) ) return memoryDriver ( )
58- return vercelRuntimeCache ( {
59- base : 'content:refs' ,
60- ttl : REF_TTL ,
61- } )
47+ return runtimeCacheDriver ( 'content:refs' , REF_TTL )
48+ }
49+
50+ /**
51+ * Per-commit data Comark knows nothing about (commit history, RSS dates).
52+ * Namespace is per-sha and keys start with `gh:`.
53+ */
54+ export function shaCacheStorage ( sha : string ) : Storage {
55+ return createStorage ( { driver : runtimeCacheDriver ( `content:${ CONTENT_PARSER_VERSION } :${ sha } ` , TTL ) } )
6256}
0 commit comments