简体   繁体   English

Symfony2学说清除缓存

[英]Symfony2 doctrine clear cache

I need to clear my doctrine's cache in Symfony 2 . 我需要在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? 还是应该在哪里找到并删除属于缓存的文件?

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+: 对于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

If you want to do it within your code (from Doctrine's documentation ) : 如果您想在代码中执行此操作(根据Doctrine的文档 ):

If you simply want to delete all cache entries you can do so with the deleteAll() method. 如果只想删除所有缓存条目,则可以使用deleteAll()方法删除。

  <?php $cacheDriver = new \\Doctrine\\Common\\Cache\\ArrayCache(); $deleted = $cacheDriver->deleteAll(); 

In case you use APC, you could also just call the code 如果您使用APC,也可以只调用代码

<?php
$deleted = apc_clear_cache() && apc_clear_cache('user');

in a php page on the same server. 在同一台服务器上的php页面中。 This is what deleteAll() method in Antho's answer does, but you do not depend on the Doctrine Classes. 这是Antho答案中的deleteAll()方法的作用,但是您不依赖于教义类。 Btw: the complete cache will be flushed - just in case you use it for non-Doctrine stuff. 顺便说一句:完整的缓存将被刷新-以防万一您将其用于非Doctrine的东西。

我以为我会疯狂使用教义结果缓存-最后,我不得不重新启动memcached。

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: 我知道这篇文章的标题是Symfony 2,但是对于那些来自Google的人来说,如果您拥有Symfony 3+,它将是:

bin/console

As opposed to: 相对于:

app/console

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: 也许这有点晚了,但是在我的情况下,学说并没有在生产环境中生成代理类,因为我将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%"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM