grails 1.3.9 应用程序中的 EHCache 默认值 [英] EHCache default values in a grails 1.3.9 application
问题描述
在 grails 1.3.9 应用程序中 ehcache 的默认值是什么?特别是我对查询缓存值感兴趣;我通过 postgres 的 psql 删除了几行,但我没有看到我的应用程序中反映的更改.我还没有将 ehcache.xml 文件添加到 conf 目录中.我什至重新启动了 grails 应用程序,数据仍然显示在报告中.没有我可以删除的缓存文件作为解决方法吗?
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?
更新:我添加了以下ehcache.xml配置文件:
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>
但是 StandardQueryCache 的 timeToIdleSeconds="30" 也不起作用.
But StandardQueryCache's timeToIdleSeconds="30" is not working either.
推荐答案
Grails 将在 conf 目录中查找 ehcache.xml.如果没有找到,它会使用你的类路径中的那个,看看 ehcache-core.jar.您将看到一个名为 ehcache-failsafe.xml 的文件,您可以在其中找到:
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"
/>
要使用查询缓存,您必须在 Datasource.groovy 中进行配置:
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'
}
虽然,就像@GreyBeardedGeek 指出的那样,EhCache 是一种直写式缓存.它只会缓存通过休眠及其二级缓存操作的对象.如果您在数据库中编写 sql 查询,它不会在您的缓存中缓存对象.
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.
这篇关于grails 1.3.9 应用程序中的 EHCache 默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!