<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd" updateCheck="false"> <defaultCache eternal="false" maxEntriesLocalHeap="10000" memoryStoreEvictionPolicy="LRU" statistics="true" /> <cache name="myCache" maxEntriesLocalHeap="1000" timeToLiveSeconds="3600"> </cache> </ehcache> import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import net.sf.ehcache.Element; public class CacheExample { public static void main(String[] args) { CacheManager cacheManager = CacheManager.newInstance("src/main/resources/ehcache.xml"); Cache cache = cacheManager.getCache("myCache"); String key = "myKey"; String value = "myValue"; Element element = new Element(key, value); cache.put(element); Element cachedElement = cache.get(key); if (cachedElement != null) { String cachedValue = (String) cachedElement.getObjectValue(); } cacheManager.shutdown(); } }


上一篇:
下一篇:
切换中文