@Caching

功能:定义复杂的缓存规则
示例:
在【缓存】@CachePut的基础上进行修改:
EmployeeService类中添加方法:

    @Caching(cacheable = {@Cacheable(value = "emp",key = "#lastName")},put = {@CachePut(value = "emp",key = "#result.id"),@CachePut(value = "emp",key = "#result.email")})public Employee getEmpByLastName(String lastName) {Employee emp = employeeMapper.getEmpByLastName(lastName);return emp;}

EmployeeController中添加方法:

    @GetMapping("/emp/lastname/{lastName}")public Employee getEmpByLastName(@PathVariable("lastName") String lastName) {Employee emp = employeeService.getEmpByLastName(lastName);return emp;}

@CacheConfig

功能: 抽取缓存的公共配置。
EmployeeService类:

package com.qublog.cache.service;import com.qublog.cache.bean.Employee;
import com.qublog.cache.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.*;
import org.springframework.stereotype.Service;@CacheConfig(cacheNames = "emp")
@Service
public class EmployeeService {@AutowiredEmployeeMapper employeeMapper;//将方法的运行结果进行缓存,以后再要相同数据,直接从缓存中获取,不用调用方法@Cacheable(/*cacheNames = {"emp"}*/)public Employee getEmp(Integer id){System.out.println("查询"+id+"号员工");Employee emp = employeeMapper.getEmpById(id);return emp;}//key也可以使用#result.id@CachePut(/*value = "emp",*/key = "#employee.id")public Employee updateEmp(Employee employee) {employeeMapper.updateEmp(employee);System.out.println("更新"+employee);return employee;}//用key来指定要清除的数据//allEntries = true@CacheEvict(/*value = "emp",*/key = "#id")public void deleteEmp(Integer id) {System.out.println("删除"+id);//employeeMapper.deleteEmp(id);
//        int i=1/0;}@Caching(cacheable = {@Cacheable(/*value = "emp",*/key = "#lastName")},put = {@CachePut(/*value = "emp",*/key = "#result.id"),@CachePut(/*value = "emp",*/key = "#result.email")})public Employee getEmpByLastName(String lastName) {Employee emp = employeeMapper.getEmpByLastName(lastName);return emp;}}

【缓存】@Caching和@CacheConfig相关推荐

  1. Spring缓存注解【@Cacheable、@CachePut、@CacheEvict、@Caching、@CacheConfig】使用及注意事项

    文章目录 一.概述 二.缓存注解种类 三.优劣势说明 四.如何使用? 五.详细介绍介绍 1)@Cacheable(常用) 1.value/cacheNames 属性 2.key属性 3.keyGene ...

  2. @Cacheable、@CachePut、@CacheEvict、@Caching、@CacheConfig详解

    文章目录 一.概述 二.缓存注解种类 三.优劣势说明 四.如何使用? 五.详细介绍介绍 1)@Cacheable(常用) 1.value/cacheNames 属性 2.key属性 3.keyGene ...

  3. 基于DDD的.NET开发框架 - ABP缓存Caching实现

    返回ABP系列 ABP是"ASP.NET Boilerplate Project (ASP.NET样板项目)"的简称. ASP.NET Boilerplate是一个用最佳实践和流行 ...

  4. Spring Cache缓存技术,Cacheable、CachePut、CacheEvict、Caching、CacheConfig注解的使用

    前置知识: 在Spring Cache缓存中有两大组件CacheManager和Cache.在整个缓存中可以有多个CacheManager,他们负责管理他们里边的Cache.一个CacheManage ...

  5. @EnableCaching、@Cacheable、@CachePut、@CacheEvict、@Caching、@CacheConfig:缓存核心注解,用来实现缓存功能...

    本文主要详解spring中缓存的使用. 背景 缓存大家都有了解过吧,主要用来提升系统查询速度. 比如电商中商品详情信息,这些信息通常不会经常变动但是会高频访问,我们可以将这些信息从db中拿出来放在缓存 ...

  6. 最全的Spring Boot缓存@Cacheable,@CachePut,@CacheEvict,@Caching,@CacheConfig注解

    1.添加依赖文件 <dependency><groupId>org.springframework.boot</groupId><artifactId> ...

  7. @Caching和@CacheConfig使用示例

    @Caching 能够为一个提供多个缓存配置 @Caching(cacheable = {@Cacheable(value = "emp",key = "#lastNam ...

  8. SpringBoot之缓存 @Caching

    背景: 当前我们使用缓存注解进行设置,发现一个问题,就是每个注解都需要有对应的函数,不过当有需求要求一个函数同时满足多个缓存的注解时候,需要进行一种最新的注解那就是 @Caching是缓存的结合体,可 ...

  9. flask缓存caching

    安装: windows安装 pip install --index-url https://pypi.douban.com/simple flask_caching 创建缓存对象: 导出: 加载到ap ...

最新文章

  1. 经典文章之java 操纵Excel[转]
  2. 计算机房做法图集,万科建筑标准工程做法通用图集(全套)
  3. 中国python之父是谁-Python之父:我们能为中国的“996”程序员做什么?
  4. paloalto防火墙执行初始配置
  5. 【Homework】说出 == 和 equals 的区别
  6. python from numpy import,python zeros()使用(from numpy import *)-Go语言中文社区
  7. okhttp3 请求html页面,OkHttp3源码详解(二) 整体流程
  8. php mysql持久连接是怎样的_怎样使PHP与MySQL数据库进行持久连接
  9. python游戏开发框架_2018年Python主流框架有哪些?最流行的Python框架
  10. ASP.NET读取自定义的config文件
  11. matlab按图像边缘抠图_Ps最全十大抠图方法都在这,最后一种万能「值得收藏」...
  12. 迅雷Chrome插件引发的Uncaught ReferenceError: xl_chrome_menu is not defined
  13. 正弦余弦算法的樽海鞘群算法
  14. 6.0系统xposed框架安装流程
  15. 机器学习入门-西瓜书总结笔记
  16. 大学的治理与改革—张维迎
  17. springboot微软文本转语音(texttospeach) java实现微软文本转语音
  18. WordPress主题 Vieu主题V4.5无授权无限制版 基于Dux主题二次开发 完美运行
  19. Qt运行提示QGtkStyle was unable to detect the current GTK+ theme.解决方法
  20. python中如何打开文件选择框

热门文章

  1. 学习笔记 - 如何增长
  2. 21、22、23、53、80、123、161、1433、3306、3389 端口的用途或协议
  3. 认识Web Workers
  4. vs2015 无法启动程序 系统找不到指定的文件
  5. 不得不了解的 iOS 15.4 beta 新特性
  6. iOS AFNetworking简介
  7. xadmin界面美化
  8. 怎么使用视频做动图?如何快速将视频转成gif图
  9. Linux学习-redis主从架构
  10. 微信如何取消企业微信消息通知 ?