laminas/laminas-cache
Laminas Cache provides flexible caching for PHP apps with storage adapters (memory, filesystem, Redis, etc.), plugins, and cache patterns. Includes PSR-6/PSR-16 support, configuration options, and utilities for improving performance and reducing expensive operations.
laminas/laminas-cache is a PSR-16-compliant caching solution with multi-adapter support (filesystem, Redis, Memcached, APC, etc.), making it a strong candidate for Laravel’s caching layer. Laravel’s built-in cache system (via Illuminate\Cache) is already PSR-16-compatible, but laminas-cache offers additional features like:
DateInterval for human-readable durations).Illuminate\Container, laminas-cache integrates via PSR-11 containers, requiring minimal adaptation (e.g., wrapping in a Laravel service provider).Memory, Apc) are fastest but volatile.laminas-cache is feasible for PSR-16 use cases (e.g., cache()->get('key')). However:
Cache facade expects Illuminate\Cache\Repository, not PSR-16. A decorator pattern or service provider bridge would be needed.predis/ext-memcached (Laravel already supports these).files driver could be replaced).ext-dba (rarely used in Laravel).laminas-cache requires explicit plugins (e.g., Serializer) for adapters like Redis. This could lead to data corruption if misconfigured.| Risk Area | Mitigation Strategy |
|---|---|
| Breaking Changes | Laravel’s cache API differs slightly (e.g., forever() vs. null TTL). |
| Performance Overhead | Benchmark adapters (e.g., Redis vs. filesystem) before production rollout. |
| Serialization Issues | Enforce Serializer plugin for non-native adapters (e.g., Redis). |
| Dependency Bloat | Only install required adapters (e.g., laminas-cache-storage-adapter-redis). |
| Laravel-Specific Quirks | Use a service provider to normalize laminas-cache with Laravel’s Cache facade. |
laminas-cache’s features critical?laminas/ packages? Training may be needed.cache() helper if wrapped in a PSR-16 facade.file, redis, memcached drivers can be replaced with laminas-cache adapters.Laravel App
├── Illuminate\Cache\Repository (current)
└── Laminas\Cache\Psr\SimpleCache\SimpleCacheDecorator (new)
├── Laminas\Cache\Storage\Adapter\* (e.g., Redis)
└── Laminas\Cache\Storage\Plugin\Serializer (if needed)
symfony/cache).laminas-cache’s features.Phase 1: PSR-16 Integration (Low Risk)
laminas-cache for PSR-16 use cases.laminas/laminas-cache and required adapters (e.g., laminas/laminas-cache-storage-adapter-redis).Psr\SimpleCache\CacheInterface to SimpleCacheDecorator.config/cache.php to use laminas-cache adapters.cache()->get/set calls.Phase 2: Advanced Features (Medium Risk)
StorageInterface directly.Cache::classCache()).Phase 3: Full Replacement (High Risk)
Cache::remember) with laminas-cache.| Laravel Cache Feature | laminas-cache Equivalent |
Notes |
|---|---|---|
cache()->get('key') |
SimpleCacheDecorator::get('key') |
PSR-16 compliant. |
cache()->put('key', $val) |
SimpleCacheDecorator::set('key', $val, $ttl) |
TTL supports DateInterval. |
cache()->forever() |
SimpleCacheDecorator::set('key', $val, null) |
Laravel’s forever() maps to null TTL. |
cache()->tags() |
Not directly supported (use StorageInterface tags) |
Requires custom implementation. |
| Class Caching | Laminas\Cache\Storage\Plugin\ClassCache |
Not in Laravel’s default cache; requires manual integration. |
| Output Buffering | Laminas\Cache\Storage\Plugin\OutputBuffer |
Experimental; may need custom Laravel middleware. |
laminas-cache vs. Laravel’s default for critical paths (e.g., Redis).cache() helper in non-critical modules first.Cache::store() to switch stores incrementally.laminas/ packages are battle-tested (used in Zend Framework).laminas-cache, document which to use.StorageInterface events).laminas-cache docs are comprehensive but assume PSR-11 containers (not Laravel’s).DateInterval parsing).Laminas\Cache\Storage\Plugin\Logger for debugging.cache()->store() to inspect active store.How can I help you explore Laravel packages today?