@Caching&@ CacheConfig |学习笔记

简介: 快速学习 @Caching&@ CacheConfig

开发者学堂课程【SpringBoot 快速掌握 - 高级应用:@Caching&@ CacheConfig】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/613/detail/9294


@Caching&@ CacheConfig

@Caching&amp 这个注解相当于是

@Cacheable@CachePut@CacheEvict 三个注解的组合@Target({ ElementType .METHOD, ElementType .TYPE})@Retention( RetentionPolicy .RUNTIME)

@Inherited

@ Documented

public@ interfaceCaching {

Cacheable[]cacheable() default{};

CachePut[]put() default{};

CacheEvict []evict() default{};

}

//@Caching 定义复杂的缓存规则

@Caching(

cacheable={

@Cacheable(value="emp",key="#lastNme")

},

put={

@CachePut(value="emp",key="#result,id"),

@CachePut(value="emp",key="#result:email")

}

)

public Employee get Emp By LastName(String lastName){  

return  emp1oyeeMapper . getEmpByLastName (lastName);

测试过程:

package com. atguigu. cache. mapper;

import...

@Mapper

public interface  EmployeeMapper {

@Select("SELECT* FROMemployeeWHEREid =#{id}")

public Employee  getEmpById (Integer id);

@Update(" UPDATEemployeeSETlastName =#(1astName),email=#(email),gender=#(gender),d_id=#(guǎi)#He  

public void updateEmp(Employee employee);

@Delete(" DELETEFROMemployeeWHEREid =#{id}")

public void delete EmpById(Integer id);

@Insert(" IMSERTINTOemployee (last/Bame,email,gender,d.id)VALUES(#(lastName),#(email),#(gender)#public  

void  insertEmployee (Employee employee);

@Select("SELECT* FROMemployeeWHERE1astName #(id}")

Employee  getEmpByLastName (String last Name);

}

又一次测试:

@ GetMapping ("/emp/lastname/{1astName}")

public Employee  getEmpByLastName (String lastName){

return  emp1oyeeService , getEmpByLastName (lastName);

按名字查,查到了"1号张三",缓存注解就起作用了,不需要查数据库。但是查lastname 时还是要查数据库。

按照l astname 的 id 查就不需要查数据库。

@ CacheConfig ( cacheNames ="emp")//抽取缓存的公共配置

所有的缓存的公共配置都看这个。

相关文章
|
Java 数据库连接 Maven
Mybatis自动生成代码提示"Cannot obtain primary key"和“ The server time zone value '�' is unrecognized or ”解决方案
Mybatis自动生成代码提示"Cannot obtain primary key"和“ The server time zone value '�' is unrecognized or ”解决方案
259 0
Mybatis自动生成代码提示"Cannot obtain primary key"和“ The server time zone value '�' is unrecognized or ”解决方案
|
存储 算法 NoSQL
Caching(二)|学习笔记
快速学习 Caching(二)
136 0
Caching(二)|学习笔记
|
存储 缓存 JSON
Caching(三)|学习笔记
快速学习 Caching(三)
169 0
Caching(三)|学习笔记
|
存储 缓存 NoSQL
Caching(一)|学习笔记
快速学习 Caching(一)
158 0
Caching(一)|学习笔记
|
Java 关系型数据库 MySQL
mybatis学习(8):The server time zone value ‘???ú±ê×??±??‘ is unrecognized or represents more
mybatis学习(8):The server time zone value ‘???ú±ê×??±??‘ is unrecognized or represents more
232 0
mybatis学习(8):The server time zone value ‘???ú±ê×??±??‘ is unrecognized or represents more
|
存储 分布式计算 负载均衡
Recovery& amp; gateway|学习笔记
快速学习 Recovery& amp; gateway。
122 0
|
网络协议 安全 应用服务中间件
WordPress with LEMP on Alibaba Cloud – Part 3 Configuring a Domain and Let's Encrypt SSL
Welcome to the third tutorial in this series about installing WordPress upon a highly performant server stack on an Alibaba ECS Cloud Instance.
2605 0
|
NoSQL PHP Redis
WordPress Caching Solutions Part 1 – Performance Benchmarking and Installing Redis Object Caching
In previous tutorials I took you through the steps to set up a new server instance, then get your WordPress sites up and running, including transactional emails.
2445 0
|
移动开发 前端开发 JavaScript
AMP for E-Commerce Part 1: Basic Building Blocks and UI Using AMP
In this three-part tutorial, we will explore how to create a fully functional e-commerce mobile application using AMP.
1649 0
AMP for E-Commerce Part 1: Basic Building Blocks and UI Using AMP
|
机器学习/深度学习 网络协议 测试技术
[20180124]测试SQLNET.EXPIRE_TIME参数3
[20180124]测试SQLNET.EXPIRE_TIME参数3.txt --//昨天测试SQLNET.EXPIRE_TIME参数时,链接如下: http://blog.
1279 0