The following code to fetch all caches is working in 2.10 (net.sf.ehcache.*)
public Map<CacheRegion, Map<Object, Element>> getCache() {
Map<CacheRegion, Map<Object, Element>> cachedData = new HashMap<CacheRegion, Map<Object, Element>>();
for (CacheRegion cacheRegion : CacheRegion.values()) {
Cache cache = cacheManager.getCache(cacheRegion.getRegionName());
Ehcache ehCache = ((EhCacheCache) cache).getNativeCache();
Map<Object, Element> cacheMap = ehCache.getAll(ehCache.getKeys());
cachedData.put(cacheRegion, cacheMap);
}
return cachedData;
}
// CacheRegion is an enum with cache keys
How can I achieve the same in EhCache 3.9 (org.ehcache.*)? I have at least 2 different types of entities being cached. I tried looking at https://stackoverflow.com/a/50389398/4669619 but that did not work for me. So far, I have replaced Element
with Object
.
public Map<CacheRegion, Map<Object, Object>> getCache() {
Map<CacheRegion, Map<Object, Object>> cachedData = new HashMap<CacheRegion, Map<Object, Object>>();
for (CacheRegion cacheRegion : CacheRegion.values()) {
Cache cache = cacheManager.getCache(cacheRegion.getRegionName());
...
}
}
Element
in 2.x example can work for any/all entity. It's not available in 3.x, so I've tried to useObject
insteadEhcache
is also not available in 3.x, so I can't store the result of((EhCacheCache) cache).getNativeCache();
in thatEhcache
not being available in 3.x meansgetAll
functionality is not available
Any suggestions/ideas will be greatly appreciated!