2017-02-13 86 views
0

我最近已經從早期的ehcache實現切換到版本3.2,所以我有一個項目的以下xml配置文件:Echache 3.2.0沒有Store.Provider發現處理配置的資源類型[offheap,disk]異常

<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文檔,您可以使用任何數據存儲層的組合但顯然這並非如此,因爲上述錯誤shows.So ...

  1. 我只能作出上述hown配置,如果我註釋掉的 offheap資源,並留下磁盤工作,但不是都。這是正常的嗎?我錯過了什麼?
  2. 根據2.7.8版本的文檔(請參閱ehcache-2.8-storage-options)提到了BigMemory作爲offHeap存儲,但是,在ehcache-3.2.0.jar中,如果我看到正確,那麼爲此目的會有某種內部映射。上面報告的錯誤是否與我沒有在項目中包含BigMemory相關?我的猜測是否定的,但如果有人能澄清,這將是很好的?

任何幫助將不勝感激。提前致謝。

回答

0

問題是更高的緩存級別(當前offheap)需要是緩存層(我們的術語用於接近緩存)。現在,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> 
+0

感謝您的幫助@亨利,並花時間清理conf。你當然是對的,我自己也想到了最後。有什麼讓我失望的是新文檔,加上事實上我認爲我在默認情況下獲得堆上存儲。還有一個問題:是否必須總是配置一個''?或者只是希望配置事件?再次感謝 –

+0

不,事件始終存在。所以你必須給它一個池,如果沒有默認的。 – Henri

0

簡而言之,目前不支持使用的磁盤層只是 offheap層。目前支持Ehcache 3.x的分層技術要求您在有多個層的時候需要層。

在這天(的Ehcache 3.1.X及以上)

支持組合:

  • 堆或offheap或磁盤或羣集(單層)
  • 堆+ offheap
  • 堆+磁盤
  • 堆+ offheap +磁盤
  • 堆+羣集
  • 堆+ offheap +羣集

該錯誤與BigMemory無關,這是Ehcache 2.x之上的商業產品。

+0

感謝您的回答,您確實是正確的以及@Henri上面。我可以驗證你的答案是否功能和明智。就BigMemory而言,我的直覺也是與錯誤無關,但爲了安全起見,我想我會檢查EhCache 3.x系列中的所有更改。不幸的是,我只能給一個+1,我不得不把它提供給上面的答案,以便花時間來編輯我的conf。再次感謝。 –