Skip to content

@Cacheable not working on interface method in Spring Boot 1.4.2+ #8331

Closed

Description

@ahmednasir91

We use Spring cache annotation

@Cacheable(cacheManager = "cacheManager", value = "cache-test", key = "'test-key2'")

This used to work well till Spring Boot 1.4.1 and the interface methods are annotated, since after upgrading to Spring Boot 1.4.3 & also tried the same on 1.4.4 the interface annotated methods have stopped working.

After digging deeper, we found it stops working with Spring Data JPA

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

If you exclude this repo, it starts working on interface methods.

This is the sample repo, to reproduce the issue https://github.com/ahmednasir91/spring-cache-test
The project has 3 branches

  • master SB v1.4.4 & Data JPA commented - Caching works on interface methods
  • cache-not-working SB 1.4.4, Data JPA enabled - Caching doesn't work for interface method
  • working-boot-1.4.1 SB 1.4.1 Data JPA enabled - Caching works on interface methods

Following are the APIs

These two have caching on interface
GET /test/hello2 
GET /test/hello

This one has on implementation
GET /test/hello-list

Activity

  1. changed the title [-]@Cacheable not working on interface in Spring Boot 1.4.3+[/-] [+]@Cacheable not working on interface method in Spring Boot 1.4.3+[/+] on Feb 20, 2017
  2. added
    status: waiting-for-triage
    on Feb 20, 2017
  3. changed the title [-]@Cacheable not working on interface method in Spring Boot 1.4.3+[/-] [+]@Cacheable not working on interface method in Spring Boot 1.4.2+[/+] on Feb 20, 2017
  4. snicoll commented on Feb 20, 2017

    @snicoll
    Member

    Thanks for the sample but I've built something that is more reasonable based on yours (you really do not need a redis store to reproduce this issue!)

    https://github.com/snicoll-scratches/test-cache-interface

    The mix between annotations on interface and concrete classes is not something we recommend doing but I can confirm that adding the JPA starter is enough to trigger the problem. It works with Spring Boot 1.4.1..RELEASE (Spring Framework 4.3.3.RELEASE) and does not anymore as of 1.4.2.RELEASE (Spring Framework 4.3.4.RELEASE).

    If I upgrade the spring framework version to use with 1.4.1.RELEASE with 4.3.4.RELEASE I am able to reproduce the problem. This looks like a framework regression but I have no idea why data jpa is triggering it.

  5. added
    type: regression
    and removed
    status: waiting-for-triage
    on Feb 20, 2017
  6. added this to the 1.4.5 milestone on Feb 20, 2017
  7. ahmednasir91 commented on Feb 20, 2017

    @ahmednasir91
    Author

    Thanks @snicoll

    We are using @Cacheable on interfaces only, just for sample i added to both interfaces & concrete class.

  8. snicoll commented on Feb 20, 2017

    @snicoll
    Member

    Ah that makes sense, thanks for clarifying.

  9. snicoll commented on Feb 20, 2017

    @snicoll
    Member

    After further investigation, this has been confirmed as a regression in Spring Framework, watch SPR-15271 for updates. I am closing this one in favour of #8248

  10. added
    status: duplicate
    and removed
    type: regression
    on Feb 20, 2017
  11. removed this from the 1.4.5 milestone on Feb 20, 2017
  12. rcollette commented on Nov 16, 2018

    @rcollette
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions