-1

When adding @Cacheable annotation on a method performing a simple Java code, on application execution, breakpoint inside the method is triggered. Does this mean that the result was not cached?

Configuration used:

spring.cache.type=redis
spring.redis.host=localhost
spring.redis.port=[port]
spring.cache.redis.time-to-live=[some value]

Note that the @Cacheable is working fine in the same project when put before a database method

user666
  • 1,750
  • 3
  • 18
  • 34
  • 1
    You are expecting an answer without adding code/configuration? Please read https://stackoverflow.com/help/how-to-ask, especially the [MVCE](https://stackoverflow.com/help/minimal-reproducible-example) part and improve your question. – M. Deinum Jul 29 '19 at 10:42

2 Answers2

0

Yes, this means that the result was not cached.

In this case, if any of the caches contains the required result, the result is returned and the method is not invoked.

Source

In order to make use of a cache, the method must be invoked with the same parameters again. However, there are limitations, as this answer points out.

Javan
  • 189
  • 1
  • 7
  • I was able to make it work by moving all code related to cached method and its sub methods to a new service class, however, my new problem is that the cache is alwatys called and never refreshed. How should I fix this? in other words, the methods code is never called. Configuration for cache time to live is: spring.cache.redis.time-to-live=60000 – user666 Jul 30 '19 at 07:31
  • Not sure what happened, but I fixed the issue by running this command in redis to clear cache: redis-cli FLUSHALL – user666 Jul 30 '19 at 07:38
0

To make it work, we need to call the method annotated with @Cacheable from a different Java class. Otherwise it doesnt work.

user666
  • 1,750
  • 3
  • 18
  • 34