cache/chain-adapter
PSR-6 cache pool chain adapter that combines multiple cache pools (e.g., APCu + Redis) into a single CachePoolChain. Part of PHP-Cache, with optional features like tagging and hierarchy via shared docs. Install with composer and use with minimal setup.
Illuminate\Cache\CacheManager). This ensures interoperability with existing Laravel cache drivers (Redis, Memcached, APCu, etc.).CachePoolChain allows defining a priority-based cache hierarchy, enabling fallback strategies (e.g., Redis → APCu → File). This aligns well with Laravel’s multi-layer caching needs (e.g., fast in-memory fallback to disk).Cache::tags() can leverage this for granular cache management.LoggerAware trait provides debugging insights, which is valuable for troubleshooting cache misses/failures in production.RedisCachePool, ApcCachePool). Laravel’s CacheManager can wrap this chain as a new driver.config/cache.php as a new driver.skip_on_failure exists, explicit error recovery (e.g., retry logic) may need customization for production-grade reliability.FileCachePool lacks tags). This could fragment cache invalidation if mixed with non-tag-aware pools.cache:clear or custom metrics)?skip_on_failure behave when all pools fail? Is there a default fallback (e.g., empty cache)?CacheStoreEvent) or tag-based invalidation?Cache facade and CacheManager. It can be registered as a new driver in config/cache.php:
'chained' => [
'driver' => 'chain',
'pools' => [
'redis', // Primary (fast)
'apcu', // Fallback (in-memory)
'file', // Last resort (disk)
],
'options' => [
'skip_on_failure' => true,
],
],
Redis, Apcu, File, Database), no new infrastructure needed.Cache::tags() for grouped invalidation (e.g., Cache::tags(['users'])->flush()).cache:clear logs or custom TTL tracking.default → chained).skip_on_failure: Set to true for graceful degradation.logger: Enable if using Laravel’s Log facade for debugging.php-cache/redis-adapter) for breaking changes.CacheStoreEvent or custom logging to track:
CachePoolChain's LoggerAware to correlate cache misses with application logs.skip_on_failure), stale data may persist. Mitigate with TTL-based invalidation.Cache::lock()) may be needed for high concurrency.| Failure Scenario | Impact | Mitigation |
|---|---|---|
All pools fail (skip_on_failure) |
Cache returns null silently. |
Set a default fallback (e.g., generate data). |
| Redis timeout | Falls back to APCu/File. | Monitor latency spikes. |
| APCu disabled | Chain skips to File/DynamoDB. | Ensure APCu is enabled in php.ini. |
| Disk full (File pool) | CacheException thrown. |
Set skip_on_failure or use DynamoDB. |
| Network partition (Redis) | Partial failures; degraded performance. | Use Redis Sentinel for HA. |
config/cache.php.How can I help you explore Laravel packages today?