doctrine/orm · error · InvalidArgumentException

No Query cache driver is configured on given EntityManager.

Error message

No Query cache driver is configured on given EntityManager.

What it means

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.

Source

Thrown at src/Tools/Console/Command/ClearCache/QueryCommand.php:39

class QueryCommand extends AbstractEntityManagerCommand
{
    protected function configure(): void
    {
        $this->setName('orm:clear-cache:query')
             ->setDescription('Clear all query cache of the various cache drivers')
             ->addOption('em', null, InputOption::VALUE_REQUIRED, 'Name of the entity manager to operate on')
             ->setHelp('The <info>%command.name%</info> command is meant to clear the query cache of associated Entity Manager.');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $ui = (new SymfonyStyle($input, $output))->getErrorStyle();

        $em    = $this->getEntityManager($input);
        $cache = $em->getConfiguration()->getQueryCache();

        if (! $cache) {
            throw new InvalidArgumentException('No Query cache driver is configured on given EntityManager.');
        }

        if ($cache instanceof ApcuAdapter) {
            throw new LogicException('Cannot clear APCu Cache from Console, it\'s shared in the Webserver memory and not accessible from the CLI.');
        }

        $ui->comment('Clearing <info>all</info> Query cache entries');

        $message = $cache->clear() ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';

        $ui->success($message);

        return 0;
    }
}

View on GitHub (pinned to d9b9ff7301)

Solutions

  1. Configure the query cache where you intend to clear it: $config->setQueryCache($adapter) or doctrine-bundle orm query_cache_driver.
  2. If you run without a query cache on purpose, drop the command from your routine.
  3. Confirm in the same CLI context: $em->getConfiguration()->getQueryCache() !== null.

Example fix

// before
$ php bin/console doctrine:orm:clear-cache:query
// InvalidArgumentException: No Query cache driver is configured...

// after
$config->setQueryCache(new Symfony\Component\Cache\Adapter\PhpFilesAdapter(
    'orm_query', 0, $cacheDir
));
Defensive patterns

Strategy: validation

Validate before calling

$config = $em->getConfiguration();
if ($config->getQueryCache() === null) {
    // no query cache configured: nothing to clear
    return 0;
}
if ($config->getQueryCache() instanceof \Symfony\Component\Cache\Adapter\ApcuAdapter) {
    // cannot clear from CLI: trigger the web-context clear instead
    return 0;
}
// run orm:clear-cache:query

Try / catch

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.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21). Data as JSON: /api/errors/09ebd775c8f235d4. Report an issue: GitHub.