cakephp/cakephp · error · InvalidArgumentException
` ` cache configuration cannot fallback to itself.
Error message
`%s` cache configuration cannot fallback to itself.
What it means
When building a cache engine fails, the framework tries the config's `fallback` engine. If `fallback` is set to the same config name, this would recurse infinitely, so _buildEngine throws immediately, chaining the original exception.
Solutions
- Set `fallback` to a different, existing config name (e.g. 'default').
- If no fallback is wanted, set 'fallback' => false so the original exception propagates.
- Verify the fallback target is itself a valid, registered configuration.
Example fix
// before
Cache::setConfig('redis', ['className' => RedisEngine::class, 'fallback' => 'redis']);
// after
Cache::setConfig('redis', ['className' => RedisEngine::class, 'fallback' => 'default']); Defensive patterns
Strategy: validation
Validate before calling
$cfg = Cache::getConfig('redis');
if ($cfg && ($cfg['fallback'] ?? null) === 'redis') {
throw new RuntimeException('fallback must differ from the config name');
} Try / catch
try {
$engine = Cache::pool('redis');
} catch (InvalidArgumentException $e) {
$prev = $e->getPrevious();
// inspect $prev for the original build failure; fix fallback config before retry
throw $prev ?? $e;
} Prevention
- Never template `fallback` from the same variable as the config key.
- Set 'fallback' => false when unsure; opt into fallbacks deliberately.
- Ensure the fallback target is a simple, always-available engine (e.g. FileEngine).
- Add a config lint step asserting fallback names differ from their own keys and exist.
When it happens
Trigger: Defining a config like Cache::setConfig('redis', ['className' => RedisEngine::class, 'fallback' => 'redis']) and the primary engine failing to build so the fallback path is entered.
Common situations: Copy-pasting a config and editing className but forgetting to update fallback; templated config generation where fallback defaults to the same key name; intending fallback to a different engine but pointing it at itself.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- Cache engine ` ` is not available.
- Cache engine ` ` is not properly configured. Check error…
- Invalid cache configuration. Multiple persistent cache…
- Invalid cache group ` `.
- The cache configuration name to use is required
AI-assisted analysis of cakephp/cakephp@1128eba9b0 (2026-09-12).
Data as JSON: /api/errors/b90564e31c772a6d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Cache/Cache.php:173
$config = static::$_config[$name];
try {
$registry->load($name, $config);
} catch (RuntimeException $e) {
if (!array_key_exists('fallback', $config)) {
$registry->set($name, new NullEngine());
trigger_error($e->getMessage(), E_USER_WARNING);
return;
}
if ($config['fallback'] === false) {
throw $e;
}
if ($config['fallback'] === $name) {
throw new InvalidArgumentException(sprintf(
'`%s` cache configuration cannot fallback to itself.',
$name,
), 0, $e);
}
$fallbackEngine = clone static::pool($config['fallback']);
assert($fallbackEngine instanceof CacheEngine);
$newConfig = $config + ['groups' => [], 'prefix' => null];
$fallbackEngine->setConfig('groups', $newConfig['groups'], false);
if ($newConfig['prefix']) {
$fallbackEngine->setConfig('prefix', $newConfig['prefix'], false);
}
$registry->set($name, $fallbackEngine);
}
if ($config['className'] instanceof CacheEngine) {
$config = $config['className']->getConfig();View on GitHub (pinned to 1128eba9b0)