cachedData
async function cachedData(request, key, decorator) {
const isBrowser = (request.headers.get("accept") || "").toLowerCase().includes("html");
try {
const cacheGetStart = Date.now();
let data = await Store.get(key);
const cacheGetTimeTaken = Date.now() - cacheGetStart;
if (decorator) data = decorator(data);
if (isBrowser) data = JSON.stringify(typeof data === 'string' ? JSON.parse(data) : data, null, 2);
const response = rawResponse(data);
response.headers.append("Server-Timing", `cache;dur=${cacheGetTimeTaken}`);
return response;
} catch (err) {
return errorResponse({ "message": err })
}
}
link