fixup! diigo-cache: the caches take their clock as a constructor argument

Past the transitional idiom: the cache logic (DiigoCacheLogic,
PublicCacheLogic in cache.ts) requires its Clock, with no default, so
cache.ts reaches no ambient time. The worker's entry module is the
edge: it makes the live clock and exports the runtime-constructed
DiigoCache/PublicCache as (ctx, env) subclasses that supply it (the
Cloudflare constraint: the runtime constructs DOs with ctx and env
only). Binding class names are unchanged, so stored state is too. The
tests' FixedClockCache extends the logic class.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-10-07 04:39:29 -05:00
1 parent cf901ded5f
commit 961515d8db
6 files changed
+53 -31

No files matched your search

+13 -14
View File
@@ -1,6 +1,9 @@
/**
* @file the cache Durable Objects: `DiigoCache` (public+private items) and
* `PublicCache` (public-only items, widely shared). They are independent
* @file the cache Durable Objects' logic: `DiigoCacheLogic` (public+private
* items) and `PublicCacheLogic` (public-only items, widely shared). Logic
* only: each requires its {@link Clock}; the worker's entry module
* (src/index.ts) is the edge that makes the live one and exports the
* runtime-constructed `DiigoCache`/`PublicCache`. They are independent
* and work the same way ({@link PagedCache}): pages are the unit of
* caching; a hit is answered from `ctx.storage.sqlite` with no diigo call;
* a miss asks the webapp instance in the cache's wiring and etches the
@@ -117,14 +120,9 @@ abstract class PagedCache extends DurableObject<CacheEnv> {
#pause?: Promise<void>;
#clock: Clock;
/** the runtime constructs DOs with (ctx, env), so the default — the
* live clock, made here at the edge, nowhere in module scope — applies;
* a subclass (tests) can pass another */
constructor(
ctx: DurableObjectState,
env: CacheEnv,
clock: Clock = { now: () => Date.now(), sleep: (ms) => new Promise((r) => setTimeout(r, ms)) },
) {
/** `clock` is required: time comes from the edge that constructs us
* (src/index.ts in the worker, tests/test-worker.ts in tests) */
constructor(ctx: DurableObjectState, env: CacheEnv, clock: Clock) {
super(ctx, env);
this.#clock = clock;
}
@@ -338,10 +336,11 @@ abstract class PagedCache extends DurableObject<CacheEnv> {
}
/**
* the private cache (export name `DiigoCache`): public+private items,
* addressed by its cache id (a webkey, held by the user).
* the private cache's logic (exported to the runtime as `DiigoCache` by
* src/index.ts): public+private items, addressed by its cache id (a
* webkey, held by the user).
*/
export class DiigoCache extends PagedCache {
export class DiigoCacheLogic extends PagedCache {
protected readonly kind = "private";
protected keep(rows: ItemRow[]): ItemRow[] {
@@ -375,7 +374,7 @@ export class DiigoCache extends PagedCache {
* (the idFromName("index") instance holds the kv mapping and is never
* wired).
*/
export class PublicCache extends PagedCache {
export class PublicCacheLogic extends PagedCache {
protected readonly kind = "public";
protected keep(rows: ItemRow[]): ItemRow[] {