您的位置:首页 > 编程语言 > Java开发

ehcache与spring,mybatis整合

2017-07-01 10:45 281 查看
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 清除此缓存中的全部数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ehcache mybatis spring