cacheput注解 用法_springboot缓存之@CachePut注解

本文介绍了SpringBoot中@CachePut注解的使用,该注解用于在调用方法后更新缓存。当数据库数据改变时,@CachePut确保同时更新缓存。在示例代码中,通过调整key的设置实现了缓存与数据库操作的同步。
摘要由CSDN通过智能技术生成

接上一节。

@CachePut:既调用方法,又更新缓存。

使用场景:当更改了数据库的某个数据,同时也更新缓存。

运行时机:先调用目标方法,然后将结果放入缓存。

packagecom.gong.springbootcache.controller;importcom.gong.springbootcache.bean.Employee;importcom.gong.springbootcache.service.EmployeeService;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.cache.annotation.CachePut;importorg.springframework.cache.annotation.Cacheable;importorg.springframework.stereotype.Controller;importorg.springframework.web.bind.annotation.GetMapping;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.ResponseBody;

@Controllerpublic classEmployeeController {

@Autowired

EmployeeService employeeService;//value:指定缓存的名字,每个缓存组件有一个唯一的名字。缓存组件由CacheManager进行管理。//key:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值