Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache annotation lookup in 4.3 finds more annotations than in 4.2 [SPR-14801] #19367

Closed
spring-issuemaster opened this issue Oct 12, 2016 · 1 comment
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Oct 12, 2016

Jakob Fels opened SPR-14801 and commented

Hi,
I'm currently trying to use caching in my application, and I noticed that Spring 4.3 breaks previously working behaviour. My implementation uses a spring cloud netflix Feign client with a fallback, the cache is only used in case of errors.
The current setup is that the main client uses @CachePut so that the data returned is always current. In case of an error the fallback acts and uses @Cacheable to return cached results or throws an exception if there are no cached results.
Due to the way spring cloud's feign integration works, the main client is an annotated interface and the fallback is a bean implementing this interface.

When using spring 4.2 (through spring boot 1.3.x) the setup works as expected. But when upgrading to 4.3 (spring boot 1.4.x) the caching no longer works.
I tracked the change in behaviour down to the introduction of the merged annotation lookup (In SpringCacheAnnotationParser).
For the fallback, the old lookup used in 4.2 would only return the @Cacheable annotation. Starting with 4.3, AnnotatedElementUtils.findAllMergedAnnotations will also return the @CachePut from the interface.
Due to both annotation being parsed for the fallback, the caching logic will ignore the @Cacheable step, since it assumes a CachePut just happened, meaning the cached values will never be returned.

I hope this description is sufficient, but I could try and provide an example if needed


Affects: 4.3.3

Issue Links:

  • #19347 @CacheConfig(cacheNames) broken when used on interface
  • #18054 Support @Cache* as merged composed annotations
  • #19836 Reliably detect @Cacheable declarations on interface methods
@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 28, 2016

Juergen Hoeller commented

It turns out that due to the explicit fallback lookup between class and interface in AbstractFallbackCacheOperationSource, SpringCacheAnnotationParser needs to use AnnotatedElementUtils.getAllMergedAnnotations instead of findAllMergedAnnotations (which has an implicit fallback to interface methods). This also affected the overriding of interface-declared annotations on class-declared methods. Fixed for 4.3.4 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.