我注意到我的網站有一個緩慢的下降,打開後debug 'org.hibernate.SQL'
我看到了麻煩在哪裏。我給自己定一個域類使用緩存....grails不使用緩存
class Foo{
...
static mapping ={
cache 'read-only'
}
String name //<-- simple data type, no associations
String description //<-- simple data type, no associations
}
我休眠的配置看起來像這樣...
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選擇問題? – cdeszaq
我的現實生活實體只有一個關聯(1到1),它也被緩存,同樣的方式 –