Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cache Laravel Package

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).

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Dependency Injection: Type-hint for 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.
  • Item Pool Use: Fetch a pool → call getItem('key') or getItems(['k1', 'k2']) → use isHit()get() or fallback logic → set()/save() the item.
  • Tagging & Batching: Use deleteItems() or clear() for bulk invalidation; many implementations (e.g., Symfony Cache) support tagging via adapter-specific extensions (TagsAwareInterface).
  • Bridge Pattern: Wrap legacy cache logic (e.g., Redis client) in a custom CacheItemPoolInterface implementation if migrating or using non-standard backends.
  • Reusability: Write domain logic against CacheItemInterface and CacheItemPoolInterface to stay implementation-agnostic — e.g., a Laravel CacheServiceProvider binding Symfony\Component\Cache\Adapter\FilesystemAdapter to CacheItemPoolInterface.

Gotchas and Tips

  • No Default Implementation: psr/cache alone won’t do anything. If CacheItemPoolInterface autowiring fails, explicitly bind a provider (e.g., bind(CacheItemPoolInterface::class, fn() => new FilesystemAdapter())).
  • Return Types Matter: v2+ enforces strict return types. For example, CacheItemInterface::get() returns mixed|null, and expiresAt()/expiresAfter() accept DateTimeInterface|null. Violating signatures in custom implementations will fail.
  • Type Narrowing in PHP 8+: Use is_hitget() safely (null check if needed); avoid assuming non-null after isHit() — the item might have expired between calls.
  • Namespace Conflict: Ensure no old CachedItemInterface or CacheException classes (e.g., from Doctrine) are autoloaded in same-namespace scenarios — use fully qualified names or import via use.
  • Migration Tip: Upgrading to v3? All methods now have typed returns. Search for CacheException usage — it now extends Throwable, so catch (\Exception $e) still works, but avoid catching non-Throwable.
  • Debugging Tip: Use 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, ...)).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4