如何在Grails中配置分布式缓存(不使用Terracota)

时间:2011-12-12 14:58:13

标签: grails ehcache

我想在两个或更多tomcats(7.0)中部署我的应用程序(Grails 1.3.5)。我设法做到没有问题,但现在我想使用RMI配置我的缓存(ehcache)。

到目前为止我所做的是创建两个ehcache.xml并将它们保存在每个tomcat的lib文件夹中。在ehcache文件中,我声明了3个缓存:

  1. defaultCache

  2. org.hibernate.cache.StandardQueryCache

  3. org.hibernate.cache.UpdateTimestampsCache

  4. 每个缓存都有一个RMI复制器。这很好但我的问题是我是否还必须在ehcache.xml文件中声明我的每个Grails域类。如果我这样做,我会有两次相同的声明:一个在ehcache.xml,第二个在类本身(我已经在类中设置了cache=true);

    class Book {
        static mapping = {
            ...
            cache true
        }
    }
    

1 个答案:

答案 0 :(得分:1)

是的,您需要在这两个地方进行设置。 ehcache.xml值配置缓存设置,但除非您为每个域类(以及可选的映射集合)启用缓存,否则它们将被忽略。

通常,您不会在defaultCache块中使用相同的设置,因为每个域类通常需要不同的设置,例如

<cache name='com.yourapp.SomeDomainClass'
       maxElementsInMemory='1000'
       eternal='true'
       maxElementsOnDisk='0'>

       <cacheEventListenerFactory
           class='net.sf.ehcache.distribution.RMICacheReplicatorFactory'
           properties='replicateAsynchronously=false
                       replicatePutsViaCopy=false,
                       replicateUpdatesViaCopy=false,
                       replicatePuts=true,
                       replicateUpdates=true,
                       replicateRemovals=true'
       />
</cache>
相关问题