Spring Cacheable vs CachePut?

后端 未结 3 1177
你的背包
你的背包 2020-12-15 04:21
@CachePut or @Cacheable(value = \"CustomerCache\", key = \"#id\")
public Customer updateCustomer(Customer customer) {
   sysout(\"i am inside updateCustomer\");
             


        
3条回答
  •  有刺的猬
    2020-12-15 05:10

    Yes, you are absolutely correct.

    @Cacheput and @Cacheable are used in conjunction.

    @Cacheable will not update the cache on every call. In order to remove the stale data, there must be a service that uses the @Cacheput that clears the stale data.

    Below answer is for the ones who are using guava caching to build cache. Using guava caching, the time interval that is applied will empty the cache after a certain period of time which is not the case with @Cacheput. @Cacheput will only update the values that are stale and hence it calls the method every time to update the cache.

    I hope my answer clears your question.

提交回复
热议问题