laravel/framework · error · InvalidArgumentException

Cache store [ ] is not defined.

Error message

Cache store [{$name}] is not defined.

What it means

CacheManager::resolve looks up the named store's configuration via getConfig(). If no matching key exists in the 'stores' array of config/cache.php (or the runtime config), getConfig returns null and the manager refuses to silently fall back. The named store must be declared before it can be used.

Solutions

  1. Add an entry under 'stores' in config/cache.php with the requested name and a valid driver.
  2. Run php artisan config:clear to remove stale cached config, then re-cache with config:cache after editing.
  3. Check for typos: the name passed to Cache::store() must exactly match a key in config/cache.php 'stores'.
  4. If the store is dynamic, register it at runtime via Cache::store('name', $repository) before first use.

Example fix

// before
Cache::store('redis-secondary')->get('key');
// config/cache.php 'stores' has only 'redis', not 'redis-secondary'

// after - in config/cache.php
'stores' => [
    // ...
    'redis-secondary' => [
        'driver' => 'redis',
        'connection' => 'cache-secondary',
    ],
],
Defensive patterns

Strategy: validation

Validate before calling

// Validate the store name is declared before resolving
$name = 'redis-secondary';
if (is_null(config("cache.stores.{$name}"))) {
    throw new \RuntimeException("Cache store [{$name}] is not declared in config/cache.php.");
}
Cache::store($name)->get('key');

Type guard

function cacheStoreIsDeclared(string $name): bool
{
    return ! is_null(config("cache.stores.{$name}"));
}

Try / catch

try {
    Cache::store($name)->get('key');
} catch (\InvalidArgumentException $e) {
    if (str_starts_with($e->getMessage(), 'Cache store [')) {
        logger()->error('Undeclared cache store requested', ['store' => $name]);
        // fall back to default
        return Cache::get('key');
    }
    throw $e;
}

Prevention

When it happens

Trigger: Calling Cache::store('redis-secondary')->get('key') when 'redis-secondary' is not declared under config/cache.php 'stores'. Also via Cache::driver('missing')->... or any code path that calls CacheManager::resolve with an undeclared store name, including config:cache dumping a stale cache config.

Common situations: Typos in store name (e.g., 'redjs' vs 'redis'). Adding a new store but forgetting to clear php artisan config:cache. Environment-specific stores defined in .env (CACHE_STORE_SECONDARY) never wired into config. Multi-tenant code selecting a tenant-scoped store that isn't registered.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/31abd383ab5d1920. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Cache/CacheManager.php:121

        });

        return $this->app->make($bindingKey);
    }

    /**
     * Resolve the given store.
     *
     * @param  string  $name
     * @return \Illuminate\Contracts\Cache\Repository
     *
     * @throws \InvalidArgumentException
     */
    public function resolve($name)
    {
        $config = $this->getConfig($name);

        if (is_null($config)) {
            throw new InvalidArgumentException("Cache store [{$name}] is not defined.");
        }

        $config = Arr::add($config, 'store', $name);

        return $this->build($config);
    }

    /**
     * Build a cache repository with the given configuration.
     *
     * @param  array  $config
     * @return \Illuminate\Cache\Repository
     *
     * @throws \InvalidArgumentException
     */
    public function build(array $config)
    {
        $config = Arr::add($config, 'store', $config['name'] ?? 'ondemand');

View on GitHub (pinned to e0f6eb3518)