How to set up distributed caching in Grails (without Terracota)

I want to deploy my application (Grails 1.3.5) in two or more cats (7.0). I managed to do this without problems, but now I want to configure the cache (ehcache) using RMI.

What I have done so far creates two ehcache.xml and saves them in the lib folder of each tomcat. Inside the ehcache files, I declared 3 stashes:

  • defaultCache

  • org.hibernate.cache.StandardQueryCache

  • org.hibernate.cache.UpdateTimestampsCache

Each cache has an RMI replicator inside. This works well, but my question is whether I should also declare each of my Grails domain classes inside the ehcache.xml file. If I do this, I will have the same declaration twice: one in ehcache.xml and the second in the class itself (I already set cache=true in the class);

 class Book { static mapping = { ... cache true } } 
+4
source share
1 answer

Yes, you need settings in both places. The ehcache.xml values ​​configure the cache settings, but they will be ignored unless you enable caching for each domain class (and possibly associated collections).

Normally, you would not use the same settings in the defaultCache block, though, since each domain class usually requires different settings, for example

 <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> 
+1
source

Source: https://habr.com/ru/post/1385906/


All Articles