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

feat(cache): add duration option #3367

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ryuapp
Copy link
Contributor

@ryuapp ryuapp commented Sep 3, 2024

closes #3340

WIP.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code
  • Add TSDoc/JSDoc to document the code

@ryuapp ryuapp marked this pull request as draft September 3, 2024 14:25
Copy link

codecov bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 45.00000% with 22 lines in your changes missing coverage. Please review.

Project coverage is 95.55%. Comparing base (dfbd717) to head (6ee6ca8).

Files with missing lines Patch % Lines
src/middleware/cache/index.ts 35.29% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3367      +/-   ##
==========================================
- Coverage   95.77%   95.55%   -0.22%     
==========================================
  Files         155      155              
  Lines        9310     9345      +35     
  Branches     2725     2742      +17     
==========================================
+ Hits         8917     8930      +13     
- Misses        393      415      +22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yusukebe
Copy link
Member

yusukebe commented Sep 5, 2024

@ryuapp

I agree with adding an "expiration" feature to the Cache Middleware. This implementation seems good. If the PR is ready, please ping me!

Copy link
Member

@usualoma usualoma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great pull request! I've commented on two of them, please check them out.

The part using Date.now(), I think we can test using vi.useFakeTimers(). If we want to be careful about testing, we may add runtime_tests, but in that case we are not sure if we can mock Date.now() cleanly or not.

src/middleware/cache/index.ts Outdated Show resolved Hide resolved
src/middleware/cache/index.ts Outdated Show resolved Hide resolved
@ryuapp
Copy link
Contributor Author

ryuapp commented Sep 29, 2024

This PR is almost complete apart from conflicts, but I have other ideas so it's on hold. The duration option works as a simple expiration time, but it is less flexible.
So I think it makes more sense to respect headers like Cache-Control the same way Cloudflare Workers does.
Options like respect.

app.use(cache({
    cacheName: 'my-app',
    cacheControl: 'max-age=60',
    respect: true, // Control cache by respecting headers like Cloudflare Workers
    wait: true,
}))

@usualoma
I'm sorry for putting it on hold for a while despite your review.
I will use your points in next PR. Thank you.

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

Successfully merging this pull request may close these issues.

Add cache expiration time
3 participants