0

我正在从 ehcache 2 迁移到 ehcache 3.5。我正在尝试使用 terracotta 开源与集群共享缓存。

下面是我的java代码,

final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
            CacheManagerBuilder.newCacheManagerBuilder()
                .with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://terr.com:9410/clustered")).autoCreate()
                    .defaultServerResource("default-resource")
                    .resourcePool("pool3", 28, MemoryUnit.MB))  
                .withCache("boxMaxFileId", CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, Integer.class,
                    ResourcePoolsBuilder.newResourcePoolsBuilder()
                        .with(ClusteredResourcePoolBuilder.clusteredShared("pool3")))) ; 
        final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true); 

        LOGGER.info(cacheManager.getStatus().toString());
        return cacheManager;

有人可以帮助我转换为 ehcache.xml

        <ehcache:service>
     <terracotta:cluster>
       <terracotta:connection url="terracotta://terr.com:9410/clustered"/>
      <terracotta:server-side-config auto-create="true">
        <terracotta:default-resource from="default-resource"/>
        <terracotta:shared-pool name="pool1" unit="MB">2</terracotta:shared-pool>
      </terracotta:server-side-config>
    </terracotta:cluster>
 </ehcache:service>


  <ehcache:cache alias="boxMaxFileId">
    <ehcache:key-type>java.lang.String</ehcache:key-type>
    <ehcache:value-type>java.lang.Integer</ehcache:value-type>
    <ehcache:resources>
      <ehcache:heap unit="entries">100</ehcache:heap>
      <ehcache:offheap unit="MB">1</ehcache:offheap>
      <terracotta:clustered-shared sharing="pool1" />
    </ehcache:resources>
  </ehcache:cache>

tc-config.xml

      <plugins>
    <config>
      <ohr:offheap-resources>
        <ohr:resource name="default-resource" unit="MB">512</ohr:resource> 
      </ohr:offheap-resources>
    </config>
  </plugins>

我收到异常,例如服务器中不存在池名称“pool1”。

4

1 回答 1

0
<?xml version="1.0" encoding="UTF-8"?>

<ehcache:config
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
  xmlns:terracotta='http://www.ehcache.org/v3/clustered'
  xmlns:ehcache='http://www.ehcache.org/v3'
  xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.1.xsd
    http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.5.xsd
    http://www.ehcache.org/v3/clustered http://www.ehcache.org/schema/ehcache-clustered-ext-3.1.xsd">

  <ehcache:service>
    <terracotta:cluster>
      <terracotta:connection url="terracotta://terr.com:9410/clustered"/>
      <terracotta:server-side-config auto-create="true">
        <terracotta:default-resource from="default-resource"/>
        <terracotta:shared-pool name="pool1" from="default-resource" unit="MB">2</terracotta:shared-pool>
      </terracotta:server-side-config>
    </terracotta:cluster>
 </ehcache:service>

  <ehcache:cache alias="boxMaxFileId">
    <ehcache:key-type>java.lang.String</ehcache:key-type>
    <ehcache:value-type>java.lang.Integer</ehcache:value-type>
    <ehcache:resources>
      <ehcache:heap unit="entries">100</ehcache:heap>
      <ehcache:offheap unit="MB">1</ehcache:offheap>
      <!--  <terracotta:clustered-dedicated unit="MB">5</terracotta:clustered-dedicated>-->
      <terracotta:clustered-shared sharing="pool1" />
    </ehcache:resources>
  </ehcache:cache>
</ehcache:config>

这是转换后的xml。对于共享,我们需要使用上述格式。

于 2018-09-06T17:27:51.770 回答