@cacheput vs @cacheable

本文深入探讨了@CachePut和@Cacheable两个Spring缓存注解的区别。@CachePut确保方法每次都执行,适用于更新缓存数据;@Cacheable仅在首次请求时执行方法,之后直接从缓存中获取数据,直至缓存过期或被刷新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@CachePut **总会执行方法**

always lets the method execute. It is generally used if you want your cache to be updated with the result of the method execution.
Example: When you want to update a stale data which is cached, instead of blowing the cache completely.

每次都会执行方法,通常在你需要更新缓存的时候使用,比如你需要更新缓存中的对象数据。

@Cacheable **只会执行一次**

will be executed only once for the given cachekey and subsequent requests won’t execute the method, until the cache expires or gets flushed.

方法只会执行一次,之后会查询缓存,除非缓存过期了或者被删除了。查询的时候就可以使用 Cacheable

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伍六七AI编程

你猜你给我1分我要不要

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值