this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: make kv tag cache logs more correct / less verbose (#920)

authored by

Victor Berchet and committed by
GitHub
424f0bcc eeb18bb7

+13 -5
+13 -5
packages/cloudflare/src/api/overrides/tag-cache/kv-next-tag-cache.ts
··· 25 25 readonly name = NAME; 26 26 27 27 async getLastRevalidated(tags: string[]): Promise<number> { 28 + const timeMs = await this.#getLastRevalidated(tags); 29 + debugCache("KVNextModeTagCache", `getLastRevalidated tags=${tags} -> time=${timeMs}`); 30 + return timeMs; 31 + } 32 + 33 + /** 34 + * Implementation of `getLastRevalidated`. 35 + * 36 + * This implementation is separated so that `hasBeenRevalidated` do not include logs from `getLastRevalidated`. 37 + */ 38 + async #getLastRevalidated(tags: string[]): Promise<number> { 28 39 const kv = this.getKv(); 29 40 if (!kv || tags.length === 0) { 30 41 return 0; ··· 36 47 const result: Map<string, number | null> = await kv.get(keys, { type: "json" }); 37 48 38 49 const revalidations = [...result.values()].filter((v) => v != null); 39 - 40 - const timeMs = revalidations.length === 0 ? 0 : Math.max(...revalidations); 41 - debugCache("KVNextModeTagCache", `getLastRevalidated tags=${tags} -> time=${timeMs}`); 42 - return timeMs; 50 + return revalidations.length === 0 ? 0 : Math.max(...revalidations); 43 51 } catch (e) { 44 52 // By default we don't want to crash here, so we return false 45 53 // We still log the error though so we can debug it ··· 49 57 } 50 58 51 59 async hasBeenRevalidated(tags: string[], lastModified?: number): Promise<boolean> { 52 - const revalidated = (await this.getLastRevalidated(tags)) > (lastModified ?? Date.now()); 60 + const revalidated = (await this.#getLastRevalidated(tags)) > (lastModified ?? Date.now()); 53 61 debugCache( 54 62 "KVNextModeTagCache", 55 63 `hasBeenRevalidated tags=${tags} lastModified=${lastModified} -> ${revalidated}`