guzzle/cache
Adds response caching to Guzzle HTTP clients. Store and reuse GET responses to cut latency and API calls, with configurable cache pools, TTLs, and cache strategies. Useful for microservices, third‑party APIs, and rate‑limited endpoints.
guzzle/cache package (Guzzle 3-era) provides HTTP response caching for Guzzle clients, reducing redundant API calls and improving performance. It fits well in architectures where:
Cache facade) or packages like spatie/laravel-guzzle may overlap or conflict.CacheMiddleware (PSR-16 compliant).cachet/cache (PSR-6/PSR-16 compatible).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Deprecated Guzzle 3 | Critical | Fork/reimplement for Guzzle 7 or use alternatives. |
| No Maintenance | High | Expect bugs; consider community forks or rewrites. |
| PSR-7 Incompatibility | High | Requires middleware refactoring. |
| Cache Backend Limits | Medium | Test with target storage (e.g., Redis, filesystem). |
| Laravel Overlap | Medium | Audit existing caching layers (e.g., Cache facade). |
FilesystemCache, RedisCache)?Cache facade, Illuminate\Contracts\Cache).// Example: Guzzle 7-compatible wrapper (pseudo-code)
use GuzzleHttp\Psr7\Request;
use Psr\Cache\CacheItemPoolInterface;
class Guzzle7CacheMiddleware {
public function __construct(private CacheItemPoolInterface $cache) {}
public function __invoke(Request $request, callable $next) {
// Implement PSR-16 cache logic for Guzzle 7.
}
}
// Before (Guzzle 3)
$client = new GuzzleHttp\Client(['cache' => new FilesystemCache(__DIR__.'/cache')]);
// After (Guzzle 7 + wrapper)
$client = new GuzzleHttp\Client([
'middleware' => [new Guzzle7CacheMiddleware(app('cache.store'))]
]);
config/http.php.predis/predis or phpredis (test connection pooling).apcu PHP extension enabled.$client->getMiddleware()->unshift($cacheMiddleware);
$this->app->bind(CacheItemPoolInterface::class, function ($app) {
return $app['cache']->store('array'); // or 'redis'
});
\Log::debug('Cache hit/miss', ['endpoint' => $request->getUri(), 'hit' => $cache->has($key)]);
| Issue Type | Responsibility | Resolution Path |
|---|---|---|
| Cache storage fail | DevOps | Check Redis/filesystem permissions. |
| Stale data | Backend | Adjust TTL or implement invalidation hooks. |
| Guzzle 3 bugs | PM/Dev | Fork or migrate to Guzzle 7. |
local driver or sync via NFS).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Cache storage unavailable | Increased API load, latency | Fallback to no-cache mode. |
| Stale cache served | Inconsistent data | Short TTLs or invalidation hooks. |
| Guzzle 3 middleware crash | Broken HTTP requests | Circuit breaker pattern. |
| Fork abandonment | Technical debt | Plan for migration to Guzzle 7. |
How can I help you explore Laravel packages today?