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 清除此缓存中的全部数据
本文介绍如何在Spring框架中配置并使用EHCache进行缓存管理,并展示了如何在MyBatis中选择不同的EHCache配置来控制是否打印日志。此外,还提供了Spring缓存注解的具体用法。
3201

被折叠的 条评论
为什么被折叠?



