@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

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

被折叠的 条评论
为什么被折叠?



