psr/cache
PSR-6 caching interfaces for PHP. Defines CacheItemPoolInterface and CacheItemInterface contracts for interoperable caching, without providing an implementation. Use with any PSR-6 compatible cache library (see Packagist providers).
The psr/cache package provides only interfaces — no implementation — so start by installing a PSR-6 compliant caching library (e.g., symfony/cache, doctrine/cache, or aws/aws-php-sns-message-validator for AWS). Run composer require psr/cache to pull in the interfaces, then choose and install a backend implementation (e.g., composer require symfony/cache). Your first use case will likely be injecting a CacheItemPoolInterface (e.g., FilesystemAdapter from symfony/cache) into services that need caching. Check the implementing library’s docs for setup — psr/cache itself has no CLI, config, or runtime behavior.
Psr\Cache\CacheItemPoolInterface in services (e.g., repositories, services fetching external APIs). Laravel’s service container auto-wires PSR interfaces by default if an implementation is available.getItem('key') or getItems(['k1', 'k2']) → use isHit() → get() or fallback logic → set()/save() the item.deleteItems() or clear() for bulk invalidation; many implementations (e.g., Symfony Cache) support tagging via adapter-specific extensions (TagsAwareInterface).CacheItemPoolInterface implementation if migrating or using non-standard backends.CacheItemInterface and CacheItemPoolInterface to stay implementation-agnostic — e.g., a Laravel CacheServiceProvider binding Symfony\Component\Cache\Adapter\FilesystemAdapter to CacheItemPoolInterface.psr/cache alone won’t do anything. If CacheItemPoolInterface autowiring fails, explicitly bind a provider (e.g., bind(CacheItemPoolInterface::class, fn() => new FilesystemAdapter())).CacheItemInterface::get() returns mixed|null, and expiresAt()/expiresAfter() accept DateTimeInterface|null. Violating signatures in custom implementations will fail.is_hit → get() safely (null check if needed); avoid assuming non-null after isHit() — the item might have expired between calls.CachedItemInterface or CacheException classes (e.g., from Doctrine) are autoloaded in same-namespace scenarios — use fully qualified names or import via use.CacheException usage — it now extends Throwable, so catch (\Exception $e) still works, but avoid catching non-Throwable.CacheItemPoolInterface::getItem($key) on unknown keys — isHit() returns false for missing/expired items, helping distinguish cache misses from null values. Log item keys to avoid key typos (e.g., Cache::remember('use', 60, ...) vs Cache::remember('users', 60, ...)).How can I help you explore Laravel packages today?