EHCache在grails 1.3.9应用程序中的默认值 [英] EHCache default values in a grails 1.3.9 application

查看:112
本文介绍了EHCache在grails 1.3.9应用程序中的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在grails 1.3.9应用程序中,ehcache的默认值是什么?特别是我对查询缓存值感兴趣;我通过postgres的psql删除了几行,并没有看到我的应用程序中反映的更改。我没有将ehcache.xml文件添加到conf目录。我甚至重新启动了Grails应用程序,数据仍然显示在报告中。



update:我添加了以下ehcache.xml配置文件:


$是否有任何缓存文件可以作为解决方法删除? b $ b

 <?xml version =1.0encoding =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也不起作用。

解决方案

Grails将在conf目录中查找ehcache.xml。如果找不到,它将使用类路径中的一个,查看ehcache-core.jar。您会看到一个名为 ehcache-failsafe.xml 的文件,您可以在其中找到:

 < ; defaultCache 
maxElementsInMemory =10000
eternal =false
timeToIdleSeconds =120
timeToLiveSeconds =120
overflowToDisk =true
maxElementsOnDisk =10000000
diskPersistent =false
diskExpiryThreadIntervalSeconds =120
memoryStoreEvictionPolicy =LRU
/>

要使用查询缓存,您必须在Datasource.groovy中进行配置:

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

虽然像@GreyBeardedGeek指出的那样, EhCache是​​一个直写式缓存。它只会缓存通过休眠和二级缓存操作的对象。如果你在数据库中写入一个sql查询,它不会缓存你的缓存中的对象。

要更深入地了解它,请查看这里此处


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.

解决方案

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.

这篇关于EHCache在grails 1.3.9应用程序中的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆