spring-cloud/spring-cloud-openfeign
Prevent duplicate cache error handler execution in FeignCachingInvocationHandlerFactory
Contribution Overview
The Engineering Context
This contribution was made to the spring-cloud/spring-cloud-openfeignopen-source repository. The work involved understanding the existing codebase, identifying the underlying engineering problem, implementing a focused solution, and validating the change against the project's existing behaviour and testing standards.
Original Issue
Cache error handling can be executed more than once for Feign clients using caching.
The interaction between Spring Cache and Feign's caching infrastructure could result in duplicate cache interception and repeated execution of cache error handling logic.
Engineering Problem
Understanding the Problem
Caching around Feign clients could involve both Spring Cache interception and FeignCachingInvocationHandlerFactory, causing cache-related handling to be invoked multiple times during a single operation.
Solution
Implementation Approach
Added a ThreadLocal-based guard around the Feign caching invocation path to prevent nested cache interception from executing repeatedly, while ensuring the guard is removed after processing completes. The PR also documents caching behaviour and related limitations for Feign clients.
Technologies
Engineering Stack
Pull Request
View the Contribution
View the pull request and the associated engineering discussion directly on GitHub.
View Pull Request on GitHub →