Caching Doctrine results Symfony2(缓存学说结果 Symfony2)
问题描述
我正在做一个 Symfony2 项目.我的项目使用数据库来存储数据和 Doctrine2 来检索该数据.
I am working on a Symfony2 project. My project uses database to store the data and Doctrine2 to retrieve that data.
随着数据库中数据的增长,查询变得非常缓慢,整个 Web 应用程序需要大约 2 分钟才能加载或根本不加载.
As the data within the database has grown the queries became very slow and the whole web app takes about 2 mins to load or does not load at all.
我可以看到自己修复此问题的唯一方法是缓存一些查询结果,但我该怎么做.除非有不同的处理方式.
The only way I can see my self fixing this is to cache some queries results but how can I do that. Unless there is different way of dealing with such issue.
推荐答案
您需要安装并配置您的缓存驱动程序 configuration(result_cache_driver
对你来说很重要).完成此操作后,您可以通过设置 useResultCache(true)
You need to have your cache driver installed and configured in doctrine configuration (result_cache_driver
is important in your case). Once you have this done you can make Doctrine
to use result cache by setting useResultCache(true)
$cachedResult = $doctrine->getManager()
->createQueryBuilder()
->(...)
->useResultCache(true)
->(...)
查看这篇博文
注意:默认情况下,在开发环境中,不会使用结果缓存
NOTE: by default, in dev environment, result cache won't be used
EDIT:因为您使用的是 DBAL
而不是使用 ORM
- SymfonyDoctrineBundle 不支持这种开箱即用的缓存,但您可以按照 自己添加此支持这个详细指南
EDIT: as you're using DBAL
and not using ORM
- SymfonyDoctrineBundle doesn't support this kind of cache out of the box, but you can add this support by yourself by following this detailed guide
这篇关于缓存学说结果 Symfony2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:缓存学说结果 Symfony2


- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01