spiral/cache
Spiral Cache provides a simple caching abstraction for Spiral/PHP apps, with support for multiple storage backends and configurable cache pools. Use it to speed up repeated operations, cache computed values, and centralize cache access and invalidation.
This package provides PSR-6 and PSR-16 interface contracts and foundational cache abstractions — not implementations. To use it, install via Composer: composer require spiral/cache. Then, implement the interfaces (e.g., Psr\SimpleCache\CacheInterface, Psr\Cache\CacheItemPoolInterface) in your own driver classes or adapters. For example, create a Redis-backed adapter by wrapping Laravel’s Cache::store('redis'). Your first real use case: type-hint CacheInterface in a service class to decouple caching logic from infrastructure.
Psr\SimpleCache\CacheInterface into repositories or services where fast, simple key-value caching is needed (e.g., get('user_' . $id)).CacheItemPoolInterface for tag-based invalidation or batch operations, e.g., inject a TaggableCacheItemPoolInterface (custom extension) to clear all cache items tagged ['products', 'variant_42'].Illuminate\Cache\Repository with a thin adapter class implementing CacheInterface, enabling Spiral-style DI in Laravel apps:
class LaravelCacheAdapter implements \Psr\SimpleCache\CacheInterface {
public function __construct(protected \Illuminate\Cache\Repository $laravelCache) {}
// map get/set/delete to $this->laravelCache->get()/put()/forget()
}
CacheInterface and assert on set() calls using ::with() to verify cache keys, values, and TTLs without hitting real storage.spiral/cache-adapter-redis) or build your own.get() returns null for misses and for cache errors by default, while PSR-6 allows distinguishing errors via isHit(). Your adapter implementation dictates behavior—ensure error handling aligns with your expectations.ShortTtlCacheFactory → ttl=60, PersistentCacheFactory → ttl=86400).get() and set() methods to surface cache misses or latency spikes during high-load scenarios.illuminate/cache already provides Psr\SimpleCache\CacheInterface via Cache::store() when psr/simple-cache is installed (it is, by default in Laravel 8+). This package adds little unless you’re migrating Spiral conventions.How can I help you explore Laravel packages today?