saloonphp/cache-plugin
Laravel-friendly Saloon plugin that adds transparent response caching to your API requests. Supports configurable cache keys, TTL, and cache stores, helping reduce duplicate calls, speed up apps, and respect rate limits with minimal setup.
saloonphp/cache-plugin (v3.1.0) remains aligned with response caching for Saloon v4+, targeting architectures requiring rate-limited API optimization, expensive endpoint caching, or read-heavy workloads. The plugin’s middleware-layer design ensures clean separation between HTTP logic (Saloon) and caching, maintaining low coupling.composer.json.withCache() or middleware hooks remains minimalistic, requiring no architectural refactoring.predis/predis, php-cache/cache-item-pool).remember())./users?role=admin)?composer.json constraints)./products)./user/profile).saloonphp/circuit-breaker) for cache failures.composer.json:
"saloon/saloon": "^4.0",
"saloonphp/cache-plugin": "^3.1"
composer require saloonphp/cache-plugin:^3.1 predis/predis
// Global cache setup (Redis example)
$cache = new PredisClient(['scheme' => 'tcp', 'host' => 'redis']);
Saloon::withCache($cache);
// Per-request caching
$response = $request->withCache()->send();
$request->withCache()->withCacheKeyFn(
fn () => 'custom_' . $request->endpoint . '_' . md5($request->queryParams)
);
$request->withCache()->send(); // Write operation
Cache::delete('key_for_' . $request->endpoint);
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Cache backend down | Fallback to uncached requests | Circuit breaker + alerts. |
| Stale cache data | Inconsistent user experience | Short TTL + ETag validation. |
| Key collision (cache misses) | Unexpected API calls | Unique key generation (include ETag). |
How can I help you explore Laravel packages today?