thecodingmachine/cache-utils
Small set of PHP cache helpers by TheCodingMachine: adapters and utilities around PSR-6/PSR-16 caches, including cache wrappers and simple tooling to standardize access, reduce boilerplate, and ease integration in frameworks and libraries.
Illuminate\Cache\CacheManager).Cache::remember() wrappers), requiring custom glue code.Redis, Memcached, FileCache) via Psr\Cache\CacheItemPoolInterface.Cache facade already implements PSR-6, so integration is theoretically straightforward.serialize()/unserialize() (PHP 8.2+ deprecations).Cache::tags() or Cache::store() methods natively.Cache::flushing).Cache::remember, Cache::put) may suffice for 80% of use cases.Cache::get() vs. CacheUtils::fetch()).spatie/laravel-cache or illuminate/cache extensions achieve the same goals?serialize()).Cache facade.file, redis, database, etc., via PSR-6 adapters.psr/cache (already in Laravel).symfony/polyfill for PHP <8.1 (if needed).Cache::get(), Cache::remember).Cache facade with CacheUtils for a subset of use cases (e.g., API response caching).use TheCodingMachine\Cache\CacheUtils;
$cache = new CacheUtils(app('cache.store'));
$data = $cache->fetch('key', fn() => $expensiveOperation(), 3600);
Cache::remember with CacheUtils where it reduces boilerplate.spatie/laravel-cache).Cache::tags() vs. CacheUtils key generation. Decide on a single strategy.CacheUtils TTLs align with Laravel’s default TTL in config/cache.php.CacheUtils doesn’t interfere with Laravel’s cache events (e.g., Cache::flushing).CacheUtils as a wrapper around Laravel’s cache (no core changes).CacheRepository).CacheUtils (if justified).CacheUtils code.CacheUtils usage patterns.Cache facade as a backup for critical paths.CacheUtils usage to monitor failures (e.g., Cache::get() vs. CacheUtils::fetch()).CacheUtils doesn’t introduce single points of failure (e.g., global key collisions).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package breaks with PHP 8.2+ | Cache failures | Polyfills or fork the package |
| Key collision in distributed cache | Stale data | Use UUIDs or Laravel’s Cache::tags() |
| TTL misconfiguration | Data freshness issues | Validate TTLs in tests |
| Cache adapter incompatibility | Partial failures | Fallback to Cache::get() |
CacheUtils patterns (vs. Laravel’s native methods).CacheUtils cheat sheet.Cache::remember vs. CacheUtils::fetch).CacheUtils to CI’s cache-related tests.How can I help you explore Laravel packages today?