INNER CODE UNIT · TypeScript
cacheKey
harvard-edge/cs249r_book · interviews/staffml-vault-worker/src/index.ts:193
function cacheKey(req: Request, releaseId: string): Request {
const url = new URL(req.url);
url.pathname = `/__vault__/${releaseId}${url.pathname}`;
return new Request(url.toString(), { method: "GET", headers: req.headers });
}
async function cachedOrCompute(
req: Request,
env: Env,
ctx: ExecutionContext,
ttlSec: number,
compute: () => Promise<Response>,
opts: { useCache: boolean } = { useCache: true },
): Promise<Response> {
// Graceful degradation when the CF Cache API isn't available (Node test
// env, vault-api local shim, or a runtime regression) — always compute
// and skip caching. Prevents crashing the handler on missing globals.
if (!opts.useCache || typeof caches === "undefined" || !caches?.default) {