i have recently switched from an older implementation of ehcache to version 3.2 so i have the following xml configuration file for a project:
<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>
with the above shown configuration i get the following exception trace that i keep truncated to conserve a bit of space but shows clearly the error:
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) ~[?:?]
I thought that according to the current 3.2 documentation you can use any combination of data storage tiers but apparently this is not the case as the above error shows.So...
Any help would be greatly appreciated. Thanks in advance.
The problem is that the higher caching level (currently offheap) needs to be a caching tier (our terminology for near caching). Right now, offheap isn't. So you need an onheap level as soon as you start having layers. Here is a working configuration.
I've also set ehcache
as default namespace to make the xml more readable. And set the defaultThreadPool
as default to prevent you from having to set it everywhere (and alternative is to add <event-dispatch thread-pool="defaultDiskPool"/>
because the event-dispatch needs a thread pool and there was no default).
<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>