简体   繁体   English

Grails未在视图中使用查询缓存

[英]Grails not using query cache in view

I've found an odd issue regarding the query cache in grails and where it's called. 我在grails中的查询缓存及其调用位置发现了一个奇怪的问题。 I've tested this several times and got the same result. 我已经对此进行了多次测试,并得到了相同的结果。

Problem: The bellow view\\gsp code hits the database every time even though i have cache:true on. 问题:即使我启用了cache:true ,波纹管视图\\ gsp代码也会每次都命中数据库。

 <g:select name="foo.thing.id" in="${Thing.findAll([cache:true])}" value="${foo.thing?.id}" />

Workaround: Pushing the query call into the controller respects the cache:true argument and it now stops hitting the database on every page load. 解决方法:将查询调用推入控制器时会遵循cache:true参数,并且现在它在每次页面加载时都不会再访问数据库。

Controller: 控制器:

def doStuff = {
  def things = Thing.findAll([cache:true]);
  return ['things':things]
}

View: 视图:

<g:select name="foo.thing.id" in="${things}" value="${foo.thing?.id}" />

I'm using Grails 1.3.7 with the following config.... 我正在使用Grails 1.3.7进行以下配置...。

hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='org.hibernate.cache.EhCacheProvider'
}

Has anyone else seen this or can describe to me why it would work differently? 有没有其他人看到过这个或者可以向我描述为什么它会以不同的方式工作?

我不确定为什么它不起作用,但这是Grails,而不是PHP-不要在视图中进行数据库访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM