缓存原则结果Symfony2 [英] Caching Doctrine results Symfony2

查看:291
本文介绍了缓存原则结果Symfony2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Symfony2项目。我的项目使用数据库存储数据和Doctrine2来检索数据。



随着数据库中的数据增长,查询变得非常慢,整个Web应用程序大约需要2分钟加载或者不加载。



我可以看到我自己修复的唯一方法是缓存一些查询结果,但我该怎么做。除非有不同的处理这种问题的方法。

解决方案

您需要安装并配置您的缓存驱动器href =http://symfony.com/doc/current/reference/configuration/doctrine.html>配置( result_cache_driver 在您的情况下很重要) 。完成之后,您可以通过设置 useResultCache(true)

$ Doctrine b
$ b

  $ cachedResult = $ doctrine-> getManager()
- > createQueryBuilder()
- > 。)
- > useResultCache(true)
- >(...)

检查此博文



注意:默认情况下,在开发环境中,结果缓存不会被使用



编辑 :您正在使用 DBAL 而不使用 ORM - SymfonyDoctrineBundle不支持这种缓存从框,但您可以通过以下详细指南


I am working on a Symfony2 project. My project uses database to store the data and Doctrine2 to retrieve that data.

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.

解决方案

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)
    ->(...)

Check this blog post

NOTE: by default, in dev environment, result cache won't be used

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆