Illuminate\Cache\CacheManager) already supports PSR-6 adapters, reducing friction for integration.Cache::tags() is limited; this bundle’s tagging could enhance granularity.AppServiceProvider can register PSR-6 services as Laravel cache drivers.CacheAdapter facade to abstract PSR-6 methods (e.g., CacheAdapter::getItem('key')).// Register PSR-6 cache as a Laravel driver
Cache::extend('psr6', function ($app) {
return new CacheAdapter($app['cache.adapter-bundle']);
});
composer.json constraints).Cache::forget() triggering PSR-6 invalidation).php-cache/adapter-redis).Cache::remember() calls coexist with PSR-6, or is a full rewrite needed?cache:clear events).illuminate/support shims.php-cache/adapter-redis, php-cache/adapter-apcu). Prefer actively maintained adapters.predis/predis directly (lower abstraction overhead).Phase 1: Proof of Concept
composer require cache/adapter-bundle php-cache/adapter-redis
Technical Evaluation).Phase 2: Hybrid Integration
Cache:: calls.// Legacy
Cache::put('user:1:posts', $posts, 60);
// New (PSR-6)
$cache = app('psr6.cache');
$item = $cache->getItem('user:1:posts');
$item->set($posts)->expiresAfter(60);
$cache->save($item);
Phase 3: Full Adoption
Cache:: with PSR-6 where tagging/hierarchy is critical.ContainerInterface. Workarounds:
illuminate/container polyfills or wrap the bundle in a Laravel-specific adapter.$container = new LaravelContainerAdapter(app());
$bundle = new CacheAdapterBundle();
$bundle->boot($container);
Cache::forgot events (or vice versa).config/cache.php:
psr6:
default: cache.adapter.redis
hierarchies:
user_data:
- cache.adapter.apcu
- cache.adapter.redis
CacheStore events or custom metrics.Cache facade.Cache::store() debugging tools alongside PSR-6 logs.CacheException) may not map cleanly to Laravel’s CacheException. Custom handlers needed:
try {
$cache->getItem('key');
} catch (\Psr\Cache\CacheException $e) {
report(new CacheAdapterException($e));
return Cache::get('fallback_key');
}
Cache::tags() + PSR-6).php-cache/adapter-redis).| Scenario | Impact | Mitigation |
|---|---|---|
| PSR-6 adapter fails | Cache unavailability | Fallback to secondary backend in hierarchy. |
| Redis downtime | API responses stale | Use APCu as fallback with shorter TTLs. |
| Tag invalidation race | Inconsistent cache state | Implement distributed locks for critical tags. |
| PHP version incompatibility | Bundle fails to load | Fork and patch for Laravel 10.x. |
getItem() over get()).public function test_tag_invalidation() {
Cache::tags(['user:1'])->put('posts', $posts);
Cache::forget('posts'); // Should invalidate PSR-6 tagged items.
$this->assertNull(app('psr6.cache')->getItem('posts')->isHit());
}
How can I help you explore Laravel packages today?