einar-hansen/laravel-psr-6-cache
Laravel package that bridges Laravel’s cache system with PSR-6. Use Laravel’s cache stores through a PSR-6 CacheItemPoolInterface for interoperability with PSR-compliant libraries, with simple configuration and drop-in integration.
Illuminate\Cache) and PSR-6 (Psr\Cache), enabling interoperability with other PSR-6-compliant libraries (e.g., Symfony components, microservices). Aligns with modular architecture goals by decoupling caching logic from Laravel-specific implementations.predis, stash). Relies entirely on Laravel’s built-in cache backends, which may limit flexibility for advanced use cases (e.g., custom cache pooling).Cache:: facade usage remains untouched unless explicitly migrated.CacheItemInterface, validating expiresAfter() behavior). Requires CI updates to verify compliance with PSR-6 contracts.Illuminate\Contracts\Cache\Store updates).CacheItem::getKey(), advanced pooling), which may require custom extensions.file driver). Could lead to runtime failures if assumptions about driver capabilities are incorrect.spatie/laravel-cache) preferable?predis)?Cache:: usage in favor of PSR-6 interfaces without breaking existing functionality?CacheItemPoolInterface)?Illuminate\Cache stack (v5.8+). Not suitable for non-Laravel PHP applications (e.g., Symfony, Lumen).Cache::put(), Cache::remember()) without PSR-6 needs.CacheItemPoolInterface extensions) not covered by this adapter.Cache:: facade calls that could be replaced with PSR-6 interfaces.config/cache.php to include the PSR-6 store:
'stores' => [
'psr6' => [
'driver' => 'psr6',
'connection' => 'redis', // Must match a Laravel cache driver
],
],
$this->app->bind(\Psr\Cache\CacheItemPoolInterface::class, function ($app) {
return new \EinarHansen\LaravelPsr6Cache\Psr6Cache(
$app['cache.store']->driver('psr6')
);
});
Cache:: calls with PSR-6 interfaces in new services first:
// Before (Laravel facade)
$data = Cache::remember('key', 3600, function () {
return $this->fetchData();
});
// After (PSR-6)
$item = $this->cache->getItem('key');
if (!$item->isHit()) {
$item->set($this->fetchData())->expiresAfter(3600);
$this->cache->save($item);
}
return $item->get();
Illuminate\Cache.file driver) may not work.CacheItemPoolInterface, CacheItemInterface) but lacks support for optional features (e.g., getKey()).CacheItem::set().Cache:: usage in high-impact services (e.g., API controllers, rate limiters).Cache:: facade usage in favor of PSR-6.Illuminate\Contracts\Cache\Store updates).spatie/laravel-cache: Actively maintained PSR-6 adapter for Laravel.league/flysystem-cache or stash.How can I help you explore Laravel packages today?