Skip to content

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
@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.

2 participants