<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<diskStore path="java.io.tmpdir" />
<defaultCache eternal="false" maxElementsInMemory="1000"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="600" memoryStoreEvictionPolicy="LFU" />
<cache name="dataDic" maxElementsInMemory="1"
eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120"
overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false"
diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
</ehcache>
ehcache.xml
<!-- 开启缓存注解 -->
<cache:annotation-driven cache-manager="cacheManager" />
<!-- ehcache缓存配置 -->
<bean id="ehcacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
<!-- spring的ehcache缓存配置 -->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcacheManager"></property>
</bean>
applicationContext.xml
CacheManager singletonManager = CacheManager.create();
Cache cache2 = singletonManager.getCache("dataDemand");//获取缓存实例
System.out.println("缓存个数======="+cache2.getSize());
List element2 = cache2.getKeys();
System.out.println("缓存所有key======="+element2);