blob: 890058af92d522c171b4214232564c6f2895482a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
"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;
|