laravel/framework · error · InvalidArgumentException

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

Error message

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

What it means

CacheManager::resolve() reads cache.stores.{name} from config; if it returns null the store name is unknown and an InvalidArgumentException is thrown. The store name comes from Cache::store('name'), Cache::store(SomeEnum::Foo), the default driver, or Cache::getProvider('name').

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 bd6b5437e6)

Solutions

  1. Add the store under 'stores' in config/cache.php with at least a 'driver' key.
  2. Correct the typo in .env CACHE_STORE (or CACHE_DRIVER on older versions) to match the store name.
  3. Clear config cache: php artisan config:clear, then re-cache after fixing.
  4. If using an enum, ensure the enum value matches the configured store key exactly.

Example fix

// before
// .env: CACHE_STORE=rediss
// config/cache.php 'stores' has no 'rediss'

// after
// .env: CACHE_STORE=redis
'stores' => [
    'redis' => [
        'driver' => 'redis',
        'connection' => 'cache',
    ],
],
Defensive patterns

Strategy: validation

Validate before calling

$name = config('cache.default');
if (! config("cache.stores.{$name}")) {
    throw new \RuntimeException("Cache store [{$name}] is not configured.");
}
Cache::store($name)->get('k');

Type guard

function cacheStoreIsDefined(string $name): bool
{
    return config("cache.stores.{$name}") !== null;
}

Try / catch

try {
    return Cache::store($name)->get('k');
} catch (\InvalidArgumentException $e) {
    if (str_contains($e->getMessage(), 'is not defined')) {
        // fall back to default driver or add the store config
        return Cache::get('k');
    }
    throw $e;
}

Prevention

When it happens

Trigger: Calling Cache::store('myredis')->get('k') when 'myredis' is not listed under 'stores' in config/cache.php. The CACHE_STORE/CACHE_DRIVER env var resolves to a name that has no entry. Using an enum value whose name isn't configured.

Common situations: Typo in .env CACHE_STORE=rediss. Renaming a store in config but forgetting to update CACHE_STORE. Referencing a store in code that only exists in another environment's config. Caching config (php artisan config:cache) with an outdated CACHE_STORE before adding the store definition.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/31abd383ab5d1920.json. Report an issue: GitHub.