pom.xml
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.8.3</version>
</dependency
ehcache.xml
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="true" monitoring="autodetect" dynamicConfig="true">
<defaultCache maxElementsInMemory="10000" eternal="false"
overflowToDisk="false" timeToIdleSeconds="500" timeToLiveSeconds="1000">
</defaultCache>
<cache name="data-cache" maxElementsInMemory="10000" overflowToDisk="false"
eternal="false" timeToIdleSeconds="500" timeToLiveSeconds="1000"
memoryStoreEvictionPolicy="LRU" transactionalMode="off">
<searchable keys="true" />
<!--可以根据Key进行查询,查询的Attribute就是keys -->
</cache>
</ehcache>
application.xml
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation=...
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
<cache:annotation-driven cache-manager="cacheManager"/>
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory"/>
</bean>
*mapper.xml
<cache eviction="LRU" flushInterval="60000" size="1024" readOnly="true"/>