hono icon indicating copy to clipboard operation
hono copied to clipboard

feat(cache): add `duration` option

Open ryuapp opened this issue 1 year ago • 3 comments

closes #3340

WIP.

The author should do the following, if applicable

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

ryuapp avatar Sep 03 '24 14:09 ryuapp

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). Report is 107 commits behind head on main.

Files with missing lines Patch % Lines
src/middleware/cache/index.ts 35.29% 22 Missing :warning:
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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features:

codecov[bot] avatar Sep 03 '24 14:09 codecov[bot]

@ryuapp

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

yusukebe avatar Sep 05 '24 06:09 yusukebe

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.

ryuapp avatar Sep 29 '24 22:09 ryuapp