Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cache expiration time #3340

Open
ryuapp opened this issue Aug 31, 2024 · 3 comments · May be fixed by #3367
Open

Add cache expiration time #3340

ryuapp opened this issue Aug 31, 2024 · 3 comments · May be fixed by #3367
Labels
enhancement New feature or request.

Comments

@ryuapp
Copy link
Contributor

ryuapp commented Aug 31, 2024

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 ryuapp added the enhancement New feature or request. label Aug 31, 2024
@ryuapp
Copy link
Contributor Author

ryuapp commented Sep 1, 2024

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 ryuapp linked a pull request Sep 3, 2024 that will close this issue
4 tasks
@Extarys
Copy link

Extarys commented Sep 12, 2024

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 🤔

@ryuapp
Copy link
Contributor Author

ryuapp commented Sep 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants