深入理解Ehcache系列(五)
Ehcache中可以使用Cache来保存需要缓存的对像,但需要把对象封装在Element的实例里。 往Cache中添加对像: CacheManager manager = CacheManager.newInstance("src/config/cache.xml"); manager.addCache("testCache"); Cache cache = singletonManager.getCache("testCache"); Element element = new Element("key", "value"); cache.put(element); 相应源码: /** * Put an element in the cache. * <p/> * Resets the access statistics on the element, which would be the case if it has previously been * gotten from a cache, and is now being put back. * <p/> * Also notifies the CacheEventListener that: * <ul> * <li>the element was put, but only if the Element was