springCache使用
来源:互联网 发布:广联达算量软件 编辑:程序博客网 时间:2024/06/06 01:44
spring自带缓存springCache使用举例:
<!--缓存-->
在applicationContext_biz中加入下列代码
<bean id="ordersBiz" class="cn.su.erp.biz.impl.OrdersBiz">
<property name="ordersDao" ref="ordersDao"></property>
<property name="cacheManager" ref="cacheManager"></property>
</bean>
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<!--设置多个cache分工做缓存-->
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" >
<property name="name" value="empCache"></property>
</bean>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" >
<property name="name" value="supplierCache"></property>
</bean>
</set>
</property>
</bean>
2.在ordersBiz中注入CacheManager/在父类中注入CacheManager
private CacheManager cacheManager;//加set方法
//从缓存中读取
Cache Cahce = cacheManager.getCache(CacheName);
String name = Cahce.get(uuid,String.class);
3.进行增删改的时候删除缓存
cacheManager.getCache("empCache").clear()//清除所有内容
cacheManager.getCache("empCache").evict(emp.getUuid())//清除该键的值
<!--缓存-->
在applicationContext_biz中加入下列代码
<bean id="ordersBiz" class="cn.su.erp.biz.impl.OrdersBiz">
<property name="ordersDao" ref="ordersDao"></property>
<property name="cacheManager" ref="cacheManager"></property>
</bean>
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<!--设置多个cache分工做缓存-->
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" >
<property name="name" value="empCache"></property>
</bean>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" >
<property name="name" value="supplierCache"></property>
</bean>
</set>
</property>
</bean>
2.在ordersBiz中注入CacheManager/在父类中注入CacheManager
private CacheManager cacheManager;//加set方法
//从缓存中读取
Cache Cahce = cacheManager.getCache(CacheName);
String name = Cahce.get(uuid,String.class);
3.进行增删改的时候删除缓存
cacheManager.getCache("empCache").clear()//清除所有内容
cacheManager.getCache("empCache").evict(emp.getUuid())//清除该键的值
阅读全文
0 0
- springCache使用
- SpringCache(Spring使用Cache)
- 以Redis为缓存模块的SpringCache使用
- springcache使用笔记001_注释驱动的 Spring cache 简单使用
- springcache使用笔记002_注释驱动的 Spring cache 按条件查询
- SpringCache--介绍(一)
- SpringCache--介绍(二)
- Springcache 应用配置说明
- springcache使用笔记003_注释驱动的 Spring cache 基本原理,注意和限制,@CacheEvict 的可靠性问题
- Redis-Cluster集群整合SpringCache
- SpringCache实现原理及核心业务逻辑(一)
- SpringCache实现原理及核心业务逻辑(二)
- SpringCache实现原理及核心业务逻辑(三)
- 使用
- 使用
- 使用
- 使用
- 使用
- swager中注解的用途
- BZOJ 2733 [HNOI2012]永无乡 Treap + 并查集
- leetcode 669. Trim a Binary Search Tree
- Spring IOC
- 微信支付 JAVA实现
- springCache使用
- Spring Cloud 熔断器
- 初始Maven1
- 【备忘】Java菜鸟到大牛学习路线培训教程
- 内存溢出和内存泄漏的区别,产生原因以及解决方案
- 关于Entity Framework中自增主键的问题
- 51nod 1267 4个数和为0(暴力)
- javascript解析json数组
- Python命令行解析argparse常用语法使用简介