1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { kv } from "https://esm.town/v/yieldray/kv";
import { request } from "https://esm.town/v/yieldray/request";
export async function reqFresh(
info: RequestInfo,
init?: RequestInit & {
query?: Record<string, string>;
},
) {
const res = await request(info, init);
const key = res.url;
const text = await res.clone().text();
try {
if ((await kv(key)) === text)
return { isFresh: false, response: res };
await kv(key, text);
}
catch (e) {
}
finally {
return { isFresh: true, response: res };
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
v7
October 23, 2023