兵马俑开放源代码无法在ecache.xml中使用-兵马俑:集群共享

时间:2018-08-25 00:53:13

标签: ehcache-3

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

下面是我的Java代码,

ts(bow, frequency=c(24*60/5), start=c(2018,1,1), end=c(2018,2,28) )

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

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;

tc-config.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>

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

1 个答案:

答案 0 :(得分: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。为了共享,我们需要使用以上格式。