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

[11.x] Optimize SetCacheHeaders to ensure error responses aren't cached #50903

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

MinaWilliam
Copy link
Contributor

@MinaWilliam MinaWilliam commented Apr 3, 2024

Problem:
Currently, error responses can be cached by the cache.headers middleware, leading to outdated errors for users.

Solution:
This PR conditionally apply caching only when the response has a successful HTTP status code.

Changes:

  • Modified the SetCacheHeaders middleware to only cache if the response is successful.

Backward Compatibility:
This change is fully backward-compatible.

Documentation:
The Laravel documentation will need to be updated to reflect the new directive.

@MinaWilliam MinaWilliam changed the title Introduce if_successful directive for conditional caching control [11.x] Introduce if_successful directive for conditional caching control Apr 3, 2024
@MinaWilliam MinaWilliam marked this pull request as draft April 3, 2024 13:37
@MinaWilliam MinaWilliam marked this pull request as ready for review April 3, 2024 13:37
@taylorotwell
Copy link
Member

Think this should just be the default behavior tbh. 👍

@taylorotwell taylorotwell merged commit 94bfff1 into laravel:11.x Apr 3, 2024
28 checks passed
@MinaWilliam MinaWilliam deleted the conditional-cache-control branch April 3, 2024 19:21
@MinaWilliam MinaWilliam changed the title [11.x] Introduce if_successful directive for conditional caching control [11.x] Optimize SetCacheHeaders to ensure error responses aren't cached Apr 3, 2024
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.

None yet

2 participants