[英]grails not using cache
我注意到我的网站运行速度慢了,打开debug 'org.hibernate.SQL'
我发现问题出在哪里。 我已经设置了一个域缓存使用....
class Foo{
...
static mapping ={
cache 'read-only'
}
String name //<-- simple data type, no associations
String description //<-- simple data type, no associations
}
我的hibernate配置看起来像这样......
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
}
我的查询看起来像这样(在网络流程中)......
def wizardFlow = {
...
def flow.foos = Foo.list([sort:"name", order:"asc", cache:true])
// def flow.foos = Foo.findAll([cache:true]) <--- same result, no caching
}
我认为查询缓存或二级缓存会阻止数据库被命中但我的日志加载了...
select ... from thing thing0_ where thing0_.id=?
select ... from thing thing0_ where thing0_.id=?
select ... from thing thing0_ where thing0_.id=?
select ... from thing thing0_ where thing0_.id=?
任何人都可以对可能发生的事情有所了解吗? 其他查询正在按照他们的意愿行事!
我正在使用Grails 1.3.7
最后,这是我的ehcache.xml ...
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" >
<diskStore path="java.io.tmpdir"/>
<cacheManagerEventListenerFactory class="" properties=""/>
<defaultCache
maxElementsInMemory="1000000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="7200"
overflowToDisk="true"
diskPersistent="false"
/>
<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="10000"
timeToIdleSeconds="300"
/>
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000"
timeToIdleSeconds="300"
/>
</ehcache>
它看起来像我们遇到的问题,基本上是N + 1选择问题。 这就是我们做的:
import org.hibernate.FetchMode as FM
...
def crit= item.createCriteria();
def itemList = crit.listDistinct
{
fetchMode "subItem", FM.JOIN
cache true
order("name","asc")
}
您应该能够将subItem切换到您关联的内容,这应该有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.