Repository navigation
New HTTP Cache Method
#60453
Unanswered
EG-Mohamed
asked this question in
Ideas
Replies: 2 comments
|
I have opened a PR with an initial implementation here: Happy to adjust the API or implementation based on maintainer feedback. |
0 replies
|
What if response carries Cache-Control headers? Take a look on kevinrob/guzzle-cache-middleware |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I would like to propose adding opt-in response caching to Laravel's HTTP Client.
Problem
When consuming external APIs, it is common to cache stable GET responses to reduce network calls, avoid rate limits, and improve performance.
Today this usually requires wrapping HTTP requests manually:
This works, but it separates cache behavior from the HTTP request definition.
Proposed API
For stale-while-revalidate caching, an array TTL would use Laravel's existing
Cache::flexible()behavior:Design
The cache key is mandatory:
Making the key mandatory keeps the feature explicit and avoids the risk of automatically generating unsafe or surprising cache keys.
Default behavior
Cache::flexible().fromCache()to determine if it was served from cache.Example
Scope
The first implementation would intentionally avoid advanced features such as cache tags, automatic key generation, custom invalidation, stale lock customization, or POST request caching.
The goal is to provide a small, explicit, Laravel-style API for the common case of caching successful external GET responses.
All reactions