spring-cloud / spring-cloud-openfeign

Support for using OpenFeign in Spring Cloud apps
Apache License 2.0
1.22k stars 786 forks source link

Cache get error handler execute twice #681

Open fureq opened 2 years ago

fureq commented 2 years ago

Describe the bug During getting elements from cache, annotated by @Cacheable on FeignClient, cache get error handler execute twice.
It looks like it is caused by change https://github.com/spring-cloud/spring-cloud-openfeign/pull/608. The flow seems to be as follows:

-> CacheInterceptor
   -> CacheAspectSupport#execute:402 (findCachedItem)
      -> handleCacheGetError 
   -> CacheAspectSupport#execute:421 (invokeOperation)
      -> FeignCachingInvocationHandlerFactory#create:53 (cacheInterceptor.invoke)
         -> CacheAspectSupport#execute:402 (findCachedItem) 
            -> handleCacheGetError

Affected spring cloud version: 2021.0.0

Sample Sample application that reproduces the problem: https://github.com/fureq/spring-feign-bug. Details are described in readme.

OlgaMaciaszek commented 2 years ago

Hello @fureq, thanks for reporting the issue and providing a sample. I was able to reproduce this.

zhangt2333 commented 3 months ago

In my project, I just set spring.cloud.openfeign.cache.enabled=false (feign.cache.enabled=false in spring-cloud-openfeign-core-3.1.0.jar) to disable twice cache operations. The org.springframework.cache.interceptor.CacheInterceptor (created at org.springframework.cache.annotation.ProxyCachingConfiguration#cacheInterceptor) already supports the @Cacheable annotation on methods within classes annotated with @FeignClient.