问题
I need to clear my doctrine's cache in Symfony 2.
There must be some way in command line for clear the cache.
Or where should I find and delete the files belonging to cache?
回答1:
app/console
will list how you can do it
app/console doctrine:cache:clear-metadata
app/console doctrine:cache:clear-query
app/console doctrine:cache:clear-result
for symfony 3+:
php bin/console
and list of comand (for copy/past from project directory):
php bin/console doctrine:cache:clear-metadata
php bin/console doctrine:cache:clear-query
php bin/console doctrine:cache:clear-result
回答2:
If you want to do it within your code (from Doctrine's documentation) :
If you simply want to delete all cache entries you can do so with the deleteAll() method.
<?php $cacheDriver = new \Doctrine\Common\Cache\ArrayCache(); $deleted = $cacheDriver->deleteAll();
回答3:
I thought I was going crazy with doctrine results caching - in the end I had to restart memcached.
回答4:
In case you use APC, you could also just call the code
<?php
$deleted = apc_clear_cache() && apc_clear_cache('user');
in a php page on the same server. This is what deleteAll() method in Antho's answer does, but you do not depend on the Doctrine Classes. Btw: the complete cache will be flushed - just in case you use it for non-Doctrine stuff.
回答5:
I know the title of this post says Symfony 2, but for those of you coming from google, if you have Symfony 3+ its gonna be:
bin/console
As opposed to:
app/console
回答6:
Maybe is a little late for this, but in my case, doctrine didn't generate the proxy classes in production, for that I change the auto_generate_proxy_classes to 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%"
来源:https://stackoverflow.com/questions/11826444/symfony2-doctrine-clear-cache