Memcache 与 Symfony/Doctrine 正在重新加载数据
在我的 symfony 项目中,我有一个“复杂”查询,如下所示:
$d = Doctrine_Core::getTable('MAIN_TABLE')
// Create the base query with some keywords
->luceneSearch($keywords)
->innerJoin('w.T1 ws')
->innerJoin('ws.T2 s')
->innerJoin('w.T3 piv')
->innerJoin('piv.T4 per')
->innerJoin('w.T5 st')
...
->innerJoin('doc.T12 docT')
->innerJoin('w.Lang lng')
->execute();
我添加了所有这些 innerJoin 以减少由于我的数据模型而导致的查询数量。实际上,所有数据都通过这个唯一的查询恢复......但查询花费了 2 到 20 秒。取决于关键字。
我决定使用内存缓存,因为数据不会一直变化。
我所做的是配置内存缓存并添加
...
->useResultCache(true)
->execute();
到我的查询中。
奇怪的是:
- 第一次(当缓存为空/刷新时),只执行一个查询
- 第二次,执行了〜130个查询,并且比第一次花费更多的时间......
那些“新”查询正在检索每个记录的“内部连接”数据。
我不明白的是为什么“内连接”数据没有保存在缓存中?
我尝试更改水合物模式,但似乎不受影响。
有人有主意吗?
In my symfony project, I have a "complex" query that looks like:
$d = Doctrine_Core::getTable('MAIN_TABLE')
// Create the base query with some keywords
->luceneSearch($keywords)
->innerJoin('w.T1 ws')
->innerJoin('ws.T2 s')
->innerJoin('w.T3 piv')
->innerJoin('piv.T4 per')
->innerJoin('w.T5 st')
...
->innerJoin('doc.T12 docT')
->innerJoin('w.Lang lng')
->execute();
I added all those innerJoin to reduce the number of query due to my data model. Actually all data are recovered with this only query.... but the query took from 2 to 20 sec. depends on keywords.
I decided to use memcache because data are not changing all the time.
What I've done is configuring memcache and adding
...
->useResultCache(true)
->execute();
to my query.
What is strange is that :
- The first time (when the cache is empty/flushed), only one query is execute
- The second time, ~130 ares executed and it take more time than the first...
Those "new" queries are retrieving data from "inner join" for each record.
What I don't undestand is why "innerjoined" data are not saved in the cache?
I tried to change the hydrate mode but it seems not to be influent.
Someone has an idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一整天的谷歌搜索、分析教义和绝望之后,我找到了一篇解释解决方案的文章:
http://shout.set Five.com/2010/04/28/using-doctrine-result-cache-with-两个深层关系/
After a whole day to googlise, to analyse doctrine and become desperate, I found an article that explain the solution:
http://shout.setfive.com/2010/04/28/using-doctrine-result-cache-with-two-deep-relations/