hono icon indicating copy to clipboard operation
hono copied to clipboard

Add cache expiration time

Open ryuapp opened this issue 1 year ago • 3 comments

What is the feature you are proposing?

Currently, with cache middleware, once it is cached, it is never updated. I'd like to keep the cache on the server side for short periods of time, but that's currently cumbersome. So, we introduce the concept of expiration time in cache middleware.

Add the duration option and store it in an internal header when the cache matches and check it, as in the example below.

app.use(cache({
    cacheName: 'my-app',
    cacheControl: 'max-age=60',
    duration: 120 // new option
    wait: true,
}))

ryuapp avatar Aug 31 '24 02:08 ryuapp

Just to add some background information, it's fair to say that cache middleware won't work properly with Deno because Cloudflare Workers respects the Cache-Control header, but Deno doesn't.

That's why we need an option like this.

ryuapp avatar Sep 01 '24 03:09 ryuapp

I don't use Deno, but wouldn't it make more sense to make Deno respect the Cache-Control header with a Deno setting instead ? That is probably not what the issue is about though :thinking:

Extarys avatar Sep 12 '24 00:09 Extarys

I don't use Deno, but wouldn't it make more sense to make Deno respect the Cache-Control header with a Deno setting instead ? That is probably not what the issue is about though 🤔

Deno is just a JavaScript runtime and will not extend Cache API. Since Cloudflare Workers is a service with CDN, it seems to be natural to consider extending the API.

ryuapp avatar Sep 12 '24 15:09 ryuapp