@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
所有发生在我们身上的事件都是一个经过仔细包装的礼物。只要我们愿意面对它有时候有点丑恶的包装,带着耐心和勇气一点一点的拆开包装的话,我们会惊喜的看到里面珍藏的礼物。
----遇见未知的自己