Symfony2 + Doctrine2不是缓存连接实体的结果 [英] Symfony2 + Doctrine2 is not caching results of joined entities

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

问题描述

我正在使用Symfony 2.0.10与Doctrine 2.1,并且具有相当简单的查询(见下文),我想使用APC(版本3.1.7,为其启用1GB内存)缓存结果,通过 useResultCache(true,600)并保持水化模式为 \Doctrine\ORM\Query :: HYDRATE_OBJECT

I am using Symfony 2.0.10 with Doctrine 2.1 and have rather simple query (see below), where I want to cache results with APC (version 3.1.7, enabled 1GB of memory for it) via useResultCache(true, 600) and keep hydration mode as \Doctrine\ORM\Query::HYDRATE_OBJECT.

问题是多对多关系( Doctrine\ORM\PersistentCollection )不会被缓存,每次当主查询结果被缓存时,连接的实体被设置为 null 。当我将水合模式设置为 \Doctrine\ORM\Query :: HYDRATE_ARRAY 时,APC中的相同查询缓存缓存,但对我来说是不可接受的解决方案,因为我不能重做许多模板,以使其工作。

The problem is that Many-to-Many relations (Doctrine\ORM\PersistentCollection) don't get cached and every time when main query results are cached the joined entities are set to null. The same query is cached well in APC when I set hydration mode to \Doctrine\ORM\Query::HYDRATE_ARRAY, but it is not acceptable solution for me, because I can't redo many templates for this to work.

请建议如何缓存APC中的所有连接实体的属性?请不要指出文档,因为我认为我已经通过心灵试图解决这个问题了解到:)

Please suggest how can I cache all joined entities' properties in APC? Please don't point to documentation, because I think I have learned it by heart trying to solve this issue :)

$property = $em
->createQueryBuilder()
->select('p,u')
->from('MyBundle:Property', 'p')
->leftJoin('p.users', 'u')
->where('p.id in (:id)')
->setParameter('id', 123)
->getQuery()
->useResultCache(true, 60)
->setHydrationMode(\Doctrine\ORM\Query::HYDRATE_OBJECT)
->getResult();



User.php



User.php

class User {
    /**
     * @ORM\ManyToMany(targetEntity="Property", mappedBy="users", cascade={"all"}, fetch="EAGER")
     */
     protected $properties;
}



Property.php



Property.php

class Property {
    /**
     * @ORM\ManyToMany(targetEntity="User", inversedBy="properties", cascade={"all"}, fetch="EAGER")
     * @ORM\JoinTable(name="user_property",
     *      joinColumns={@ORM\JoinColumn(name="property_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}
     * )
     */
     protected $users;
}


推荐答案

这是Doctrine JIRA问题与最接近问题描述的缓存问题相关:

Here is the Doctrine JIRA issue related to a caching issue which is the closest to the problem's description:

http://www.doctrine-project.org/jira/browse/DDC-217
https://github.com/doctrine/doctrine2/issues/2861

我的意见是在Doctrine 2.2

My opinion is that point is fixed in Doctrine 2.2

这篇关于Symfony2 + Doctrine2不是缓存连接实体的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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