diff options
Diffstat (limited to 'cli/bench/testdata/npm/hono/dist/middleware/cache/index.js')
-rw-r--r-- | cli/bench/testdata/npm/hono/dist/middleware/cache/index.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cli/bench/testdata/npm/hono/dist/middleware/cache/index.js b/cli/bench/testdata/npm/hono/dist/middleware/cache/index.js new file mode 100644 index 000000000..890058af9 --- /dev/null +++ b/cli/bench/testdata/npm/hono/dist/middleware/cache/index.js @@ -0,0 +1,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; |