对于Symfony 3+:
php bin/console
将列出所有命令,以下是与缓存相关的命令:
php bin/console doctrine:cache:clear-metadata
php bin/console doctrine:cache:clear-query
php bin/console doctrine:cache:clear-result
在Symfony 3之前:
app/console
将列出如何实现它的方法。
app/console doctrine:cache:clear-metadata
app/console doctrine:cache:clear-query
app/console doctrine:cache:clear-result
app/console list
来显示所有命令,或者使用 app/console list doctrine
来仅显示 'doctrine' 命名空间中的命令。 - caponicadoctrine:cache:clear-result
命令,但它没有起作用。我还尝试了 bin/doctrine orm:clear-cache:result
命令,但也没有效果。我正在使用 memcache
。 - Sithu如果你想在代码中实现它(来自Doctrine文档):
If you simply want to delete all cache entries you can do so with the deleteAll() method.
$cacheDriver = new \Doctrine\Common\Cache\ArrayCache(); $deleted = $cacheDriver->deleteAll();
<?php
$deleted = apc_clear_cache() && apc_clear_cache('user');
在同一服务器上的 PHP 页面中。这就是 Antho 答案中 deleteAll() 方法所做的,但你不依赖于 Doctrine 类。顺便说一下:完整的缓存将被清除 - 以防你将其用于非 Doctrine 的东西。
我曾经对Doctrine的结果缓存感到困惑 - 最终我不得不重启Memcached。
我知道这篇文章的标题是Symfony 2,但是对于从谷歌过来的读者,如果你使用的是Symfony 3+,那么:
bin/console
app/console
auto_generate_proxy_classes
设置为 true:#symfony2&3 app/config/config.yml
#symfony4 config/packages/doctrine.yaml (by default true since 4.2)
doctrine:
orm:
auto_generate_proxy_classes: true #"%kernel.debug%"
public function __construct(..., private KernelInterface $kernel
和
$this->kernel->shutdown(); //RESET ALL
/** @var SiteService $siteService */
$siteService = $this->kernel->getContainer()->get(SiteService::class); //Important kernel->getContainer()
/** @var Site[] $sites */
$sites = $siteService->repository->getByInstalledSites();
foreach ($sites as $site) {
dump('Domain:'. $site->getDomain());
$session = new Session();
$session->set('db_user', $site->getUser());
$session->set('db_password', $this->getDecryptPassword($site->getPassword()));
$session->set('db_name', $site->getDatabaseName())
$user = $this->userService->getById(1);
dump($user);
//what you want to do ...
$this->kernel->shutdown(); //Running All bundles shutdown and container set null
$this->kernel->boot(); // services_resetter->reset and preboot -> loading bundles&Containers and all bundles set container & run boot
}
$this->em->clear(MyEntity::class);
rm -rf app/cache/*
没有起作用? - Vitalii Zurianapp/console cache:clear
命令只会清除 Symfony (app) 缓存。我认为它不会清除 Doctrine 缓存。 - caponica