diigo-cache: pace diigo calls only; cache hits don't wait

page() ran the 500 ms pacing gate before the cache check, so every hit
waited too: a fill rerun skipping 166 cached pages took ~80 s and
looked like a start from scratch. The gate now sits after the hit
check (re-checking storage once through it, in case a request ahead
had just etched the page).

Regression test: the fixed-clock test cache records its sleeps; a miss
sleeps once, three hits add none (failed before: 4 sleeps).

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-10-07 05:06:17 -05:00
1 parent f5d57f73d3
commit fd16c7db53
3 files changed
+43 -8

No files matched your search

+16 -1
View File
@@ -12,8 +12,23 @@ export { default } from "../src/index.js";
/** 2026-10-07T12:00:00Z */
export const FIXED_NOW = Date.UTC(2026, 9, 7, 12, 0, 0);
/** a fixed clock that records each sleep it is asked for */
export class FixedClockCache extends DiigoCacheLogic {
#sleeps: number[] = [];
constructor(ctx: DurableObjectState, env: CacheEnv) {
super(ctx, env, { now: () => FIXED_NOW, sleep: async () => {} });
const sleeps: number[] = [];
super(ctx, env, {
now: () => FIXED_NOW,
sleep: async (ms) => {
sleeps.push(ms);
},
});
this.#sleeps = sleeps;
}
/** the sleeps so far (test hook) */
async sleeps(): Promise<number[]> {
return [...this.#sleeps];
}
}