1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-30 02:59:11 -05:00
denoland-deno/cli/bench/testdata/npm/hono/dist/middleware/cache/index.js
2022-08-19 15:54:54 +05:30

32 lines
944 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cache = void 0;
const cache = (options) => {
if (options.wait === undefined) {
options.wait = false;
}
const addHeader = (response) => {
if (options.cacheControl)
response.headers.append('Cache-Control', options.cacheControl);
};
return async (c, next) => {
const key = c.req;
const cache = await caches.open(options.cacheName);
const response = await cache.match(key);
if (!response) {
await next();
addHeader(c.res);
const response = c.res.clone();
if (options.wait) {
await cache.put(key, response);
}
else {
c.executionCtx.waitUntil(cache.put(key, response));
}
}
else {
return response;
}
};
};
exports.cache = cache;