Echache 3.2.0没有发现Store.Provider处理配置的资源类型[offheap,disk]异常

时间:2017-02-13 13:09:40

标签: ehcache ehcache-bigmemory

我最近从旧的ehcache实现切换到版本3.2所以我有一个项目的以下xml配置文件:

<eh:config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xmlns:eh='http://www.ehcache.org/v3'
  xsi:schemaLocation="http://www.ehcache.org/v3    
  http://www.ehcache.org/schema/ehcache-core-3.0.xsd">
<eh:persistence directory="C:\foo\bar\Cache-Persistence"/>
<eh:thread-pools> 
  <eh:thread-pool alias="defaultDiskPool" min-size="1" max-size="3"/>
</eh:thread-pools> 
<eh:disk-store thread-pool="defaultDiskPool"/>
<eh:cache-template name="PROC_REQTemplate">
  <eh:key-type>java.lang.String</eh:key-type>
  <eh:value-type>java.lang.String</eh:value-type>
  <eh:expiry>
    <eh:ttl>640</eh:ttl>
  </eh:expiry> 
  <eh:resources> 
    <eh:offheap unit="MB">500</eh:offheap>
    <eh:disk unit="GB" persistent="true">3</eh:disk>
  </eh:resources>
  <eh:disk-store-settings thread-pool="defaultDiskPool"/>
</eh:cache-template>
<eh:cache alias="proc_req_cache" uses-template="PROC_REQTemplate"/>
</eh:config> 

使用上面显示的配置我得到以下异常跟踪,我一直被截断以节省一些空间但显示错误:

java.lang.IllegalStateException: No Store.Provider found to handle configured resource types [offheap, disk] from {org.ehcache.impl.internal.store.heap.OnHeapStore$Provider, org.ehcache.impl.internal.store.tiering.TieredStore$Provider, org.ehcache.impl.internal.store.offheap.OffHeapStore$Provider, org.ehcache.impl.internal.store.disk.OffHeapDiskStore$Provider}
at org.ehcache.core.internal.store.StoreSupport.selectStoreProvider(StoreSupport.java:80) ~[?:?]
at org.ehcache.core.EhcacheManager.getStore(EhcacheManager.java:440) ~[?:?]
at org.ehcache.core.EhcacheManager.createNewEhcache(EhcacheManager.java:311) ~[?:?]
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:260) ~[?:?]
at org.ehcache.core.EhcacheManager.init(EhcacheManager.java:567) ~[?:?]

我认为根据当前的3.2文档,您可以使用任何数据存储层的组合,但显然情况不是这样,因为上面的错误显示。所以......

  1. 如果我注释掉,我只能使上面提到的配置工作 offheap资源并保留磁盘,但不能同时保留两者。这是正常的吗?我错过了什么?
  2. 根据2.7.8版本,文档(请参阅此处ehcache-2.8-storage-options)提到BigMemory为offHeap商店,但是在ehcache-3.2.0.jar中,如果我看到正确的是有某种内部地图为了这个目的。上面报告的错误是否与我在项目中不包含BigMemory这一事实有关?我的猜测是否定的,但是如果有人能澄清那会很好吗?
  3. 非常感谢任何帮助。提前致谢。

2 个答案:

答案 0 :(得分:0)

简而言之,目前不支持使用 一个offheap层的磁盘层。当前Ehcache 3.x对分层的支持要求您拥有多层的层。

此时支持的组合(Ehcache 3.1.x及更高版本):

  • 堆或offheap或磁盘或群集(单层)
  • 堆+ offheap
  • 堆+磁盘
  • 堆+ offheap +磁盘
  • heap + clustered
  • 堆+ offheap + clustered

该错误与BigMemory无关,这是Ehcache 2.x之上的商业产品。

答案 1 :(得分:0)

问题是较高的缓存级别(当前是offheap)需要是缓存层(我们的近缓存术语)。现在,脱机不是。因此,一旦开始拥有图层,就需要一个onheap级别。这是一个有效的配置。

我还将ehcache设置为默认命名空间,以使xml更具可读性。并将defaultThreadPool设置为默认值,以防止您必须在任何地方设置它(另一种方法是添加<event-dispatch thread-pool="defaultDiskPool"/>,因为事件派发需要一个线程池而且没有默认值。)

<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
           xmlns='http://www.ehcache.org/v3'
           xsi:schemaLocation="http://www.ehcache.org/v3
  http://www.ehcache.org/schema/ehcache-core-3.0.xsd">

    <persistence directory="C:\foo\bar\Cache-Persistence"/>

    <thread-pools>
        <thread-pool alias="defaultDiskPool" min-size="1" max-size="3" default="true"/>
    </thread-pools>

    <cache-template name="PROC_REQTemplate">
        <key-type>java.lang.String</key-type>
        <value-type>java.lang.String</value-type>
        <expiry>
            <ttl>640</ttl>
        </expiry>
        <resources>
            <heap unit="entries">1</heap>
            <offheap unit="MB">500</offheap>
            <disk unit="GB" persistent="true">3</disk>
        </resources>
    </cache-template>

    <cache alias="proc_req_cache" uses-template="PROC_REQTemplate"/>
</config>
相关问题