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

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

问题描述

我正在使用带有 Doctrine 2.1 的 Symfony 2.0.10 并且有相当简单的查询(见下文),我想通过 useResultCache(true, 600) 并保持水合模式为 DoctrineORMQuery::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 DoctrineORMQuery::HYDRATE_OBJECT.

问题是多对多关系 (DoctrineORMPersistentCollection) 没有被缓存,每次当主查询结果被缓存时,连接的实体都被设置为 .当我将 hydration mode 设置为 DoctrineORMQuery::HYDRATE_ARRAY 时,相同的查询在 APC 中缓存得很好,但这对我来说是不可接受的解决方案,因为我无法为此重做很多模板工作.

The problem is that Many-to-Many relations (DoctrineORMPersistentCollection) 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 DoctrineORMQuery::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(DoctrineORMQuery::HYDRATE_OBJECT)
->getResult();

用户.php

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

属性.php

class Property {
    /**
     * @ORMManyToMany(targetEntity="User", inversedBy="properties", cascade={"all"}, fetch="EAGER")
     * @ORMJoinTable(name="user_property",
     *      joinColumns={@ORMJoinColumn(name="property_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORMJoinColumn(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-217https://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天全站免登陆