spring
<!-- 配置ehcache -->
<bean id="cacheManagerFactory"class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
<property name="shared" value="true" />
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="cacheManagerFactory" />
</bean>
<!-- 启动ehcache缓存注解 -->
<cache:annotation-driven cache-manager="cacheManager" />
mybatis
不打印日志
<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
打印日志
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
@Cacheable(value="user",key="#mobile")
添加缓存 value=缓存名 key=缓存中may的key
@CacheEvict(value="user",allEntries=true)
清除缓存 allEntries=true 清除此缓存中的全部数据