'use client'; /** * The live `QueryCache` implementation — the client half of the service the Tag * in `#infrastructure/query-cache.ts` names. It delegates to the runtime-level * store (`./suspensable-store.ts`), scoped to one runtime so it only touches * this `mount`'s cache — never another's. * * The store is keyed by `runtimeScopeOf(runtime)`, but the cache must exist * *before* the runtime it belongs to (it is merged into the runtime's own * layer), so it closes over a scope **thunk**: the runtime boundary sets the * scope right after `ManagedRuntime.make`, and `ManagedRuntime.make` is lazy, * so no service can resolve the cache before the scope is set. A `null` scope * (never the case after wiring) matches nothing and reports zero. */ import * as Equal from 'effect/Equal'; import type { QueryCacheApi } from '#infrastructure/query-cache.ts'; import { invalidateByTag, refetchByKey } from '#infrastructure/react/suspensable-store.ts'; export const makeQueryCache = (scope: () => string | null): QueryCacheApi => ({ invalidate: (tag) => { const current = scope(); return current === null ? 0 : invalidateByTag(current, (t) => Equal.equals(t, tag)); }, refetch: (key) => { const current = scope(); return current === null ? 0 : refetchByKey(current, key); }, });