feat(cache): add `duration` option
closes #3340
WIP.
The author should do the following, if applicable
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:
- Flaky Tests Detection - Detect and resolve failed and flaky tests
- JS Bundle Analysis - Avoid shipping oversized bundles
@ryuapp
I agree with adding an "expiration" feature to the Cache Middleware. This implementation seems good. If the PR is ready, please ping me!
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.