问题
What are ehcache's default values in a grails 1.3.9 application ? In particular I'm interested in the query cache value; I deleted a couple of rows via postgres' psql and I don't see the changes reflected in my app. I haven't added the ehcache.xml file to the conf directory. I even restarted the grails app and the data still shows up in the report. Aren't there any cache files I can delete as a workaround?
update: I added the following ehcache.xml configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" >
<diskStore path="/tmp/ehcache_t2"/>
<cacheManagerEventListenerFactory class="" properties=""/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToLiveSeconds="120">
</defaultCache>
<cache name="org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="10000"
timeToIdleSeconds="300"
/>
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000"
timeToIdleSeconds="30"
/>
</ehcache>
But StandardQueryCache's timeToIdleSeconds="30" is not working either.
回答1:
Grails will look for a ehcache.xml in the conf directory. If not found, it will use the one in your classpath, take a look at the ehcache-core.jar. You'll see a file named ehcache-failsafe.xml where you'll find:
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
To make use of the query cache, you must have configured in your Datasource.groovy:
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='org.hibernate.cache.EhCacheProvider'
}
Although, like @GreyBeardedGeek pointed out, EhCache is a write-through cache. It will only cache objects that are manipulated via hibernate and its second level cache. If you write a sql query in your database, it will not cache objects in your cache.
To understand more deeply about it, take a look here and here.
来源:https://stackoverflow.com/questions/11813489/ehcache-default-values-in-a-grails-1-3-9-application