-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🐛 fix: Align cache middleware with RFC7231 #3283
🐛 fix: Align cache middleware with RFC7231 #3283
Conversation
WalkthroughThis pull request enhances the caching middleware in the Fiber framework by introducing a new variable, Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (5)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3283 +/- ##
==========================================
- Coverage 84.14% 84.08% -0.06%
==========================================
Files 116 116
Lines 11553 11557 +4
==========================================
- Hits 9721 9718 -3
- Misses 1402 1407 +5
- Partials 430 432 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
middleware/cache/cache.go (1)
51-56
: LGTM! Consider adding a comment to explain TeaPot status code inclusion.The list of cacheable status codes aligns well with RFC 7231. However, it would be helpful to add a comment explaining why the TeaPot status code (418) is included despite not being cacheable according to the RFC.
var cacheableStatusCodes = []int{ fiber.StatusOK, fiber.StatusNonAuthoritativeInformation, fiber.StatusNoContent, fiber.StatusPartialContent, fiber.StatusMultipleChoices, fiber.StatusMovedPermanently, + // TeaPot status code is included for benchmarking purposes despite not being cacheable according to RFC 7231 fiber.StatusNotFound, fiber.StatusMethodNotAllowed, fiber.StatusGone, fiber.StatusTeapot, fiber.StatusRequestURITooLong, fiber.StatusNotImplemented, }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
middleware/cache/cache.go
(2 hunks)middleware/cache/cache_test.go
(1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
middleware/cache/cache_test.go
929-929: error returned from external package is unwrapped: sig: func strconv.Atoi(s string) (int, error)
(wrapcheck)
🪛 GitHub Check: lint
middleware/cache/cache_test.go
[failure] 929-929:
error returned from external package is unwrapped: sig: func strconv.Atoi(s string) (int, error) (wrapcheck)
🪛 GitHub Actions: golangci-lint
middleware/cache/cache_test.go
[error] 929-929: Error returned from external package strconv.Atoi is unwrapped. Consider wrapping the error using fmt.Errorf or custom error types.
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: unit (1.23.x, windows-latest)
- GitHub Check: Compare
- GitHub Check: repeated
🔇 Additional comments (2)
middleware/cache/cache.go (1)
180-184
: LGTM! The implementation effectively prevents caching of non-cacheable status codes.The conditional check is well-placed and correctly implements the PR objective of preventing responses with non-cacheable status codes from being stored in the cache.
middleware/cache/cache_test.go (1)
934-995
: LGTM! Comprehensive test coverage for non-cacheable status codes.The test covers all categories of HTTP status codes (informational, successful, redirection, client error, and server error responses) ensuring thorough validation of the caching behavior.
Caution An unexpected error occurred while opening a pull request: Not Found - https://docs.github.com/rest/git/refs#get-a-reference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change to improve performance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change to improve performance
@gaby |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
@miyamo2 thanks for the customization can you please expand the documentation of the caching resources and mention that we are now following RFC7231 and link to it so that more info can be found ?
|
after the docs update i will merge it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/middleware/cache.md
(1 hunks)docs/whats_new.md
(1 hunks)
🧰 Additional context used
🪛 Markdownlint (0.37.0)
docs/middleware/cache.md
30-30: Expected: 0 or 2; Actual: 2
Trailing spaces
(MD009, no-trailing-spaces)
🪛 GitHub Check: markdownlint
docs/middleware/cache.md
[failure] 30-30: Trailing spaces
docs/middleware/cache.md:30:91 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md009.md
🪛 GitHub Actions: markdownlint
docs/middleware/cache.md
[error] 30-30: MD009/no-trailing-spaces: Trailing spaces [Expected: 0 or 2; Actual: 2]
🪛 LanguageTool
docs/whats_new.md
[grammar] ~736-~736: Do not use the singular ‘a’ before the plural noun ‘conditions’.
Context: ...ache management, allowing you to define a custom conditions for invalidating cache entries. Addit...
(VB_A_JJ_NNS)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: unit (1.23.x, windows-latest)
- GitHub Check: repeated
- GitHub Check: Compare
🔇 Additional comments (2)
docs/middleware/cache.md (1)
13-37
: Well-documented cache behavior!The documentation clearly explains which HTTP status codes are cacheable according to RFC7231, includes the special case for status code 418, and provides helpful references to MDN and the RFC specification.
🧰 Tools
🪛 Markdownlint (0.37.0)
30-30: Expected: 0 or 2; Actual: 2
Trailing spaces(MD009, no-trailing-spaces)
🪛 GitHub Check: markdownlint
[failure] 30-30: Trailing spaces
docs/middleware/cache.md:30:91 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md009.md🪛 GitHub Actions: markdownlint
[error] 30-30: MD009/no-trailing-spaces: Trailing spaces [Expected: 0 or 2; Actual: 2]
docs/whats_new.md (1)
736-737
: Great documentation of cache improvements!The documentation effectively communicates both the new cache invalidator feature and the alignment with RFC7231 standards for cacheable status codes.
🧰 Tools
🪛 LanguageTool
[grammar] ~736-~736: Do not use the singular ‘a’ before the plural noun ‘conditions’.
Context: ...ache management, allowing you to define a custom conditions for invalidating cache entries. Addit...(VB_A_JJ_NNS)
docs/middleware/cache.md
Outdated
- `501: Not Implemented` | ||
|
||
Additionally, `418: I'm a teapot` is not originally cacheable but is cached by this middleware. | ||
If the status code is other than these, you will always get an `unreachable` cache status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix trailing spaces.
Remove the trailing spaces at the end of line 30 to resolve the markdownlint error.
-If the status code is other than these, you will always get an `unreachable` cache status.
+If the status code is other than these, you will always get an `unreachable` cache status.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
If the status code is other than these, you will always get an `unreachable` cache status. | |
If the status code is other than these, you will always get an `unreachable` cache status. |
🧰 Tools
🪛 Markdownlint (0.37.0)
30-30: Expected: 0 or 2; Actual: 2
Trailing spaces
(MD009, no-trailing-spaces)
🪛 GitHub Check: markdownlint
[failure] 30-30: Trailing spaces
docs/middleware/cache.md:30:91 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md009.md
🪛 GitHub Actions: markdownlint
[error] 30-30: MD009/no-trailing-spaces: Trailing spaces [Expected: 0 or 2; Actual: 2]
@@ -733,7 +733,8 @@ The adaptor middleware has been significantly optimized for performance and effi | |||
|
|||
### Cache | |||
|
|||
We are excited to introduce a new option in our caching middleware: Cache Invalidator. This feature provides greater control over cache management, allowing you to define a custom conditions for invalidating cache entries. | |||
We are excited to introduce a new option in our caching middleware: Cache Invalidator. This feature provides greater control over cache management, allowing you to define a custom conditions for invalidating cache entries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix grammar in the cache invalidator description.
There's a grammar issue in the sentence.
-We are excited to introduce a new option in our caching middleware: Cache Invalidator. This feature provides greater control over cache management, allowing you to define a custom conditions for invalidating cache entries.
+We are excited to introduce a new option in our caching middleware: Cache Invalidator. This feature provides greater control over cache management, allowing you to define custom conditions for invalidating cache entries.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
We are excited to introduce a new option in our caching middleware: Cache Invalidator. This feature provides greater control over cache management, allowing you to define a custom conditions for invalidating cache entries. | |
We are excited to introduce a new option in our caching middleware: Cache Invalidator. This feature provides greater control over cache management, allowing you to define custom conditions for invalidating cache entries. |
🧰 Tools
🪛 LanguageTool
[grammar] ~736-~736: Do not use the singular ‘a’ before the plural noun ‘conditions’.
Context: ...ache management, allowing you to define a custom conditions for invalidating cache entries. Addit...
(VB_A_JJ_NNS)
@ReneWerner87 |
Sure, i check it tomorrow morning |
Description
This pull request updates the cache middleware to avoid caching uncacheable status codes.
This change improves cache accuracy and saves cache storage size.
https://datatracker.ietf.org/doc/html/rfc7231#section-6.1
See also:
However, for 418: TeaPot, although not actually cacheable, it continues to be cacheable since it is used in benchmark tests.
Thank you.
Fixes -
Type of change
Checklist
/docs/
directory for Fiber's documentation.Benchmarks(on GitHub Codespaces)
Before
After