{"record":{"id":"049b03afbef43eda","repo":"doctrine/orm","slug":"no-second-level-cache-is-configured-on-the-given-e-049b03","errorCode":null,"errorMessage":"No second-level cache is configured on the given EntityManager.","messagePattern":"No second-level cache is configured on the given EntityManager\\.","errorType":"console","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Tools/Console/Command/ClearCache/QueryRegionCommand.php","lineNumber":70,"sourceCode":"Finally, be aware that if <info>--flush</info> option is passed,\nnot all cache providers are able to flush entries, because of a limitation of its execution nature.\nEOT);\n    }\n\n    protected function execute(InputInterface $input, OutputInterface $output): int\n    {\n        $ui = (new SymfonyStyle($input, $output))->getErrorStyle();\n\n        $em    = $this->getEntityManager($input);\n        $name  = $input->getArgument('region-name');\n        $cache = $em->getCache();\n\n        if ($name === null) {\n            $name = Cache::DEFAULT_QUERY_REGION_NAME;\n        }\n\n        if (! $cache instanceof Cache) {\n            throw new InvalidArgumentException('No second-level cache is configured on the given EntityManager.');\n        }\n\n        if ($input->getOption('flush')) {\n            $cache->getQueryCache($name)\n                ->getRegion()\n                ->evictAll();\n\n            $ui->comment(\n                sprintf(\n                    'Flushing cache provider configured for second-level cache query region named <info>\"%s\"</info>',\n                    $name,\n                ),\n            );\n\n            return 0;\n        }\n\n        if ($input->getOption('all')) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Tools/Console/Command/ClearCache/QueryRegionCommand.php#L52-L88","documentation":"orm:clear-cache:region:query evicts a second-level-cache query region (the default region when no region name is given). Like the other region commands it requires the second-level cache to be enabled: $em->getCache() returns null otherwise, and the command throws InvalidArgumentException because there are no query regions to evict.","triggerScenarios":"Running orm:clear-cache:region:query [region-name] on an EntityManager whose configuration never enabled the second-level cache; running it in an environment (dev/staging) where SLCache is off while prod has it on.","commonSituations":"Deploy scripts copied between environments; projects using ->enableResultCache()/setCacheable(true) without enabling the second-level cache; setup code that clears regions before SLCache is configured.","solutions":["Enable the second-level cache (doctrine-bundle: orm.second_level_cache) where you intend to clear query regions.","Remove the command from environments that do not use the second-level cache.","Guard scripted runs with $em->getCache() instanceof Cache."],"exampleFix":"# before\n$ php bin/console doctrine:orm:clear-cache:region:query my_region\n# InvalidArgumentException: No second-level cache is configured...\n\n# after: enable SLCache, then\n$ php bin/console doctrine:orm:clear-cache:region:query my_region","handlingStrategy":"type-guard","validationCode":"use Doctrine\\ORM\\Cache;\n\nif (! $em->getCache() instanceof Cache) {\n    // second-level cache not enabled: no query regions to evict\n    return 0;\n}\n// safe to run orm:clear-cache:region:query [region]","typeGuard":"use Doctrine\\ORM\\Cache;\nuse Doctrine\\ORM\\EntityManagerInterface;\n\n/** @psalm-assert Cache $cache */\nfunction assertSlcCache(EntityManagerInterface $em): void\n{\n    $cache = $em->getCache();\n    assert($cache instanceof Cache);\n}","tryCatchPattern":"Catch \\InvalidArgumentException around the command invocation in scripts and downgrade to an informational note ('SLCache not enabled here') rather than a pipeline failure.","preventionTips":["Only schedule region-clear commands where SLCache is enabled.","If queries use setCacheable(true), ensure the second-level cache is configured too.","Keep region names in configuration constants so command arguments never drift."],"tags":["doctrine-orm","second-level-cache","console","cache","cli","symfony"],"backgroundTag":"missing-cache-configuration","analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}