csa/guzzle-cache-middleware
PSR-7/PSR-18 middleware adding HTTP response caching to Guzzle clients. Cache GET/HEAD requests, reduce repeated network calls, and plug into common cache storage backends. Install via Composer and integrate in your Guzzle handler stack.
Cache facade or config/cache.php), it can be wrapped in a Laravel service provider to align with Laravel’s caching backends (Redis, Memcached, file, database).Illuminate\Cache can be injected to standardize caching logic (e.g., using Cache::remember() under the hood).Psr\SimpleCache\CacheInterface). Laravel’s cache drivers (Redis, file, etc.) are PSR-16 compliant, ensuring seamless integration.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Archived Status | Project is archived (no active maintenance). | Evaluate fork/alternatives (e.g., guzzlehttp/cache, symfony/http-client). |
| Laravel-Specific Gaps | No native Laravel integration (e.g., no Cache facade support). |
Abstract cache logic into a Laravel service layer or wrapper class. |
| Cache Invalidation | Manual cache invalidation required (e.g., stale data if API responses change). | Implement TTL-based invalidation or event listeners for API updates. |
| Dependency Bloat | Adds Guzzle as a dependency if not already present. | Use Laravel’s HTTP client (which bundles Guzzle) to avoid duplication. |
| Testing Overhead | Requires mocking Guzzle middleware for unit tests. | Use Laravel’s HTTP tests or mocks for Guzzle middleware. |
Cache facade (Redis, file, etc.) via PSR-16.GuzzleCacheMiddleware) for dependency injection.guzzlehttp/cache: More actively maintained, but lacks Laravel-specific features.Cache::remember(): For simple cases, but lacks Guzzle’s middleware flexibility.config/services.php.| Component | Compatibility | Notes |
|---|---|---|
| Laravel Version | 8.x+ (for HTTP client) or 7.x+ (with Guzzle 6/7). | Avoid Laravel 5.x due to Guzzle 6+ requirement. |
| PHP Version | 7.4+ (Guzzle 6/7 requirement). | Laravel 8+ supports PHP 8.0+, which is ideal. |
| Cache Drivers | Redis, Memcached, file, database (PSR-16 compliant). | Test with the primary cache driver in use. |
| Guzzle Version | 6.0–7.x (package supports 6+). | Laravel 8+ uses Guzzle 7 by default. |
| Middleware Order | Must be placed after error middleware but before logging/retries. | Guzzle middleware stack order is critical for correct caching behavior. |
Guzzle\HandlerStack logging to inspect middleware execution.Cache::store() methods for debugging cache hits/misses.How can I help you explore Laravel packages today?