问题
I am trying to upgrade Ehcache for my Project from 2.6 to 3.0 version.
Any replacement for net.sf.ehcache.Element and CacheExceptionHandler.
Less documentation on Ehcache 3, Can anyone give some tips for upgrading Ehacahe to version 3.
回答1:
Ehcache 3 is by design a major rework of the APIs so there are indeed large differences with Ehcache 2.x.
net.sf.ehcache.Elementhas been completely removed, theorg.ehcache.CacheAPI is now closer (but not identical) to ajava.util.concurrent.ConcurrentMap. This means you simplyput(K key, V value)andV get(K key)- no need for a wrapper object.- A consequence of that is that you can no longer set a per mapping expiration. However, a custom
org.ehcache.expiry.Expirycan be configured which can have mapping specific answers.
- A consequence of that is that you can no longer set a per mapping expiration. However, a custom
- The concept of
CacheExceptionHandleris gone. In Ehcache 3 the approach is that aCacheshould never be the source of an exception. If agetfails, it is valid to returnnullas long as you always return that until the nextput. If aputfails, there is effectively no difference with a validputfollowed by immediate eviction. Ehcache 3 follows these principles. However there are cache setups, mostly around cache-through and distributed caches, where consistency can be a challenge. Expect a solution to this to come soon to the Ehcache 3.x line.
As for a more complete documentation on the topic of migrating from one to the other, that is indeed something that still needs to be done.
来源:https://stackoverflow.com/questions/42070863/ehcache-migration-from-2-6-to-3-00