{"record":{"id":"09ebd775c8f235d4","repo":"doctrine/orm","slug":"no-query-cache-driver-is-configured-on-given-entit","errorCode":null,"errorMessage":"No Query cache driver is configured on given EntityManager.","messagePattern":"No Query cache driver is configured on given EntityManager\\.","errorType":"console","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Tools/Console/Command/ClearCache/QueryCommand.php","lineNumber":39,"sourceCode":"class QueryCommand extends AbstractEntityManagerCommand\n{\n    protected function configure(): void\n    {\n        $this->setName('orm:clear-cache:query')\n             ->setDescription('Clear all query cache of the various cache drivers')\n             ->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on')\n             ->setHelp('The <info>%command.name%</info> command is meant to clear the query cache of associated Entity Manager.');\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        $cache = $em->getConfiguration()->getQueryCache();\n\n        if (! $cache) {\n            throw new InvalidArgumentException('No Query cache driver is configured on given EntityManager.');\n        }\n\n        if ($cache instanceof ApcuAdapter) {\n            throw new LogicException('Cannot clear APCu Cache from Console, it\\'s shared in the Webserver memory and not accessible from the CLI.');\n        }\n\n        $ui->comment('Clearing <info>all</info> Query cache entries');\n\n        $message = $cache->clear() ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';\n\n        $ui->success($message);\n\n        return 0;\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":55,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Tools/Console/Command/ClearCache/QueryCommand.php#L21-L55","documentation":"orm:clear-cache:query clears the DQL query cache through $em->getConfiguration()->getQueryCache(). When no query cache was configured the getter returns null and the command throws InvalidArgumentException instead of pretending to clear anything. The command additionally refuses APCu backends with a separate LogicException.","triggerScenarios":"Running orm:clear-cache:query on an EntityManager whose configuration never called setQueryCache() (doctrine-bundle: query_cache_driver); a CLI kernel that boots a cache-less configuration while the web app caches.","commonSituations":"ORM 3 upgrades where the old default query cache is gone; deploy scripts clearing all caches before the config exists; dev environments with caching intentionally disabled.","solutions":["Configure the query cache where you intend to clear it: $config->setQueryCache($adapter) or doctrine-bundle orm query_cache_driver.","If you run without a query cache on purpose, drop the command from your routine.","Confirm in the same CLI context: $em->getConfiguration()->getQueryCache() !== null."],"exampleFix":"// before\n$ php bin/console doctrine:orm:clear-cache:query\n// InvalidArgumentException: No Query cache driver is configured...\n\n// after\n$config->setQueryCache(new Symfony\\Component\\Cache\\Adapter\\PhpFilesAdapter(\n    'orm_query', 0, $cacheDir\n));","handlingStrategy":"validation","validationCode":"$config = $em->getConfiguration();\nif ($config->getQueryCache() === null) {\n    // no query cache configured: nothing to clear\n    return 0;\n}\nif ($config->getQueryCache() instanceof \\Symfony\\Component\\Cache\\Adapter\\ApcuAdapter) {\n    // cannot clear from CLI: trigger the web-context clear instead\n    return 0;\n}\n// run orm:clear-cache:query","typeGuard":null,"tryCatchPattern":"Catch \\InvalidArgumentException and \\LogicException around the command in deploy tooling; map each to an actionable message ('configure query_cache_driver' / 'clear APCu from the web process') instead of failing silently.","preventionTips":["Configure an explicit query cache in every environment that runs cache commands.","Avoid APCu for caches you must clear from the CLI; prefer Redis or filesystem adapters.","Document which caches are cleared by which process (web vs CLI) in your deploy runbook."],"tags":["doctrine-orm","console","cache","query-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"}