我正在使用 EhCache 来存储我的应用程序对象的有限大小缓存,但是在升级其版本后,我在使用cache.get(...)时遇到了这个异常:
java.lang.ClassCastException: net.sf.ehcache.store.chm.SelectableConcurrentHashMap$DummyPinnedKey cannot be cast to br.com.project.util.VttcElement
有人知道我们是否应该在缓存键中实现任何新接口吗?
这是我改编的代码:
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
private VttcElementCache() {
CacheManager cacheManager = CacheManager.create(METAINFFileLoader.getInputStream("ehcache.xml"));
cache = cacheManager.getCache("br.com.project.util.VttcElement");
}
private void load(int id, long idf) {
cache.put(new Element(new VttcElement(id, idf), "1"));
}
private String get(VttcElement vttcElement) {
Element element = cache.get(vttcElement); //The exception is thrown here!
(String) return elemente.getValue();
}