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

Tag Interop Laravel Package

cache/tag-interop

Provides two interoperable interfaces that add tag support to PSR-6 caching, enabling consistent tagging and invalidation across cache implementations. Built by contributors from Symfony, PHP-Cache, and Drupal; MIT licensed and installable via Composer.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer (composer require cache/tag-interop). This package provides only interfaces—no concrete implementations—so it must be used alongside a cache pool that supports tagging (e.g., cache/file-filesystem, cache/array-adapter with tagging support, or custom pools implementing the interfaces). First, locate the two core interfaces: Cache\TagInterop<TaggableCacheItemPoolInterface> (extends PSR-6’s CacheItemPoolInterface) and Cache\TagInterop<TaggableCacheItemInterface> (extends PSR-6’s CacheItemInterface). These extend PSR-6 with optional tagging capabilities (tag(), invalidateTags()), enabling developers to build tag-based cache invalidation strategies—e.g., busting all cache items related to a "user:123" or "product:456" tag on updates.

Implementation Patterns

  • Conditional Tagging: In repositories or services, wrap cache saves with ->tag('entity:type:123') before save().
  • Bulk Invalidation: Use invalidateTags(['user:123', 'theme:dark']) on a tagged pool to clear related entries without knowing individual keys.
  • PSR-6 + Tagging Hybrid: Leverage tagged pools in Laravel via custom Cache\Store implementations or in Symfony with cache.adapter.taggable services—integrate via factory or decorator.
  • Dependency Injection: Inject TaggableCacheItemPoolInterface type-hinted services for testability; mock tagging behavior in unit tests.
  • PSR-6/PSR-16 Bridge: For hybrid systems, adapt PSR-16 cache calls into tagged workflows by securing a tagged pool for write-heavy paths (e.g., API responses, rendered views).

Gotchas and Tips

  • ⚠️ No default implementation: This package only defines interfaces. Confusingly, composer require cache/tag-interop alone won’t give tagging behavior—you must pair it with a tagged-capable pool (e.g., php-cache/file-filesystem v1.2+).
  • ⚠️ PSR-6 Compatibility: Though tagged pools extend PSR-6, not all PSR-6 implementations support tagging—always verify instanceof TaggableCacheItemPoolInterface before calling tag() or invalidateTags().
  • Debugging: Use var_dump(get_class($pool)) to confirm the pool implements the interface; invalidateTags() silently fails on non-tagged pools—check logs for null returns.
  • Extension Points: For custom pools, implement both interfaces (e.g., class MyPool implements TaggableCacheItemPoolInterface) and manage tag→keys mappings manually in save(), invalidateTags().
  • ⚠️ PHP 8 Support: Version 1.1.0+ is required for PHP 8+—older versions use PHPDoc for return types and may cause autoloading issues in modern projects.
  • Future-proofing: Since these are intended for PSR, prefer the Cache\TagInterop\ namespace (not Cache\Taggable\*)—the codebase is stable but deprecated in favor of upcoming PSR-6 extensions.
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