chenzero
chenzero

Reputation: 13

spring with ehcache, cache missing in non-cacheable function calls

This question is really hard to describe clearly just in text. shortly, if call a function marked with @Cacheable directly, all as expected. however, if call this @Cacheable function in another function without @Cacheable, cache hits is not as expected.

please see the code: http://www.devbeacon.com/d/cache1.zip

Thank you very much!

Upvotes: 1

Views: 193

Answers (1)

Stephane Nicoll
Stephane Nicoll

Reputation: 33091

The documentation is pretty explicit about that

In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual caching at runtime even if the invoked method is marked with @Cacheable - considering using the aspectj mode in this case.

Your internal method call completely bypass the proxy. query2 should have the @Cacheable as well. If you don't want that, you need to use the AspectJ mode instead.

Upvotes: 3

Related Questions