<dependency> <groupId>javax.cache</groupId> <artifactId>cache-api</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.ehcache</groupId> <artifactId>ehcache</artifactId> <version>3.8.1</version> </dependency> import javax.cache.Cache; import javax.cache.CacheManager; import javax.cache.Caching; import javax.cache.configuration.MutableConfiguration; public class CacheExample { public static void main(String[] args) { CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(); MutableConfiguration<String, String> configuration = new MutableConfiguration<>(); Cache<String, String> cache = cacheManager.createCache("myCache", configuration); cache.put("key1", "value1"); cache.put("key2", "value2"); System.out.println(cache.get("key1")); System.out.println(cache.get("key2")); } } <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd" updateCheck="false"> <defaultCache maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" diskSpoolBufferSizeMB="30" maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU"> </defaultCache> </ehcache>


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