如何集群 Ehcache 用作 Hibernate 的二级缓存

use*_*742 5 java caching hibernate ehcache cluster-computing

在我的基于 Spring MVC + Hibernate 的 Web 应用程序中,我使用 Ehcache 作为 Hibernate 二级缓存。它在单个服务器上运行得很好。但是我需要将我的应用程序迁移到集群环境。只是想知道如何使 Ehcache 作为 Hibernate 的二级缓存在集群环境中工作?提前致谢。

Vla*_*cea 3

您需要使用 Teracotta 来集群 Ehcache,并将您的ehcache.xml配置更改为能够感知集群环境的male Ehcache:

<cache name="cacheRegion"
    maxEntriesLocalHeap="1000"
    eternal="false"
    timeToIdleSeconds="3600"
    timeToLiveSeconds="1800"">
  <persistence strategy="distributed"/>
  <terracotta clustered="true" consistency="eventual" />
</cache>
Run Code Online (Sandbox Code Playgroud)

如果您不想购买 Teracotta 许可证,则可以设置复制缓存。您可以使用RMI 复制来协调 Cache 节点:

<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
multicastGroupPort=4446, timeToLive=32"/>
Run Code Online (Sandbox Code Playgroud)

  • 与 Ehcache 2.10.0 匹配的 [Terracotta 4.3.0](http://terracotta.org/downloads/open-source/catalog) 再次提供了开源产品。免责声明:我为 Terracotta 工作 (2认同)