@cacheput vs @cacheable

@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

posted @ 2018-09-14 10:44  六七十三  阅读(35)  评论(0编辑  收藏  举报