cache/void-adapter
PSR-6 “void” (null/blackhole) cache pool that never stores anything and always returns empty cache items. Useful for disabling caching in tests or no-op environments. Part of the PHP-Cache organization.
void-adapter excels as a PSR-6-compliant null cache, ideal for:
CacheManager and Psr6Cache drivers, enabling seamless integration via Cache::driver('void').composer require cache/void-adapter; no external dependencies.Cache facade and CacheManager.config/cache.php:
'void' => [
'driver' => 'cache',
'pool' => Cache\VoidCachePool::class,
],
Cache::driver(config('cache.void') ? 'void' : 'redis')).getItemsByTag or getItemTags.void negates caching benefits entirely.Cache::tags()) that could break?Cache::driver('void') or cache()->store('void').Psr6Cache driver (if configured).composer.json (dev dependency):
composer require --dev cache/void-adapter
.env:
CACHE_DRIVER=void
$pool = new \Cache\VoidCachePool();
config/cache.php:
'void' => [
'driver' => 'cache',
'pool' => \Cache\VoidCachePool::class,
],
AppServiceProvider):
if ($this->app->environment('production') && config('cache.fallback_to_void')) {
Cache::extend('void', fn() => new \Cache\VoidCachePool());
}
$driver = config('features.use_void_cache') ? 'void' : 'redis';
Cache::driver($driver)->get('key');
getItem, commit, clear, etc.).getItemsByTag exist but return empty results.Cache::tags() works but doesn’t persist.Cache::store('void')->remember() ignores expiration.composer.json (dev).void is detected in non-dev environments.void if primary cache fails.CacheStoreEvent).void to specific features (e.g., experimental APIs).php-cache organization for PSR-6 changes (minimal risk).void usage in production:
if (app()->environment('production') && Cache::getStore()->getDriver() === 'void') {
Log::warning('Void cache driver detected in production!');
}
| Scenario | Impact | Mitigation |
|---|---|---|
| Accidental production use | All cached data lost; app behaves as if cache is disabled. | Restrict void driver to non-production via config/environment checks. |
| Tag-based logic reliance | Code assuming tags work may break (e.g., Cache::tags(['foo'])->get()). |
Document tagging limitations; use void only where tags aren’t critical. |
| CI/CD pipeline reliance | Tests may pass falsely if they assume cache persistence. | Add explicit warnings if void is used in CI. |
| Laravel event caching | Events may fail to persist if cached. | Avoid using void for event caching; use Redis or database instead. |
| Session storage | Session data resets on every request. | Use file or database drivers for sessions; avoid void. |
void as a development-only or fallback tool.void behavior in non-critical paths.VoidCachePool in unit tests to avoid accidentalHow can I help you explore Laravel packages today?