spring 使用 ehcache,在不可缓存的函数调用中缺少缓存
spring with ehcache, cache missing in non-cacheable function calls
这个问题真的很难用文字描述清楚。
简而言之,如果直接调用标有@Cacheable 的函数,
一切如预期。但是,如果在另一个中调用此 @Cacheable 函数
没有@Cacheable 的功能,缓存命中率不符合预期。
请看代码:
http://www.devbeacon.com/d/cache1.zip
非常感谢!
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.
您的内部方法调用完全绕过了代理。 query2
也应该有 @Cacheable
。如果你不想那样,你需要改用 AspectJ 模式。
这个问题真的很难用文字描述清楚。 简而言之,如果直接调用标有@Cacheable 的函数, 一切如预期。但是,如果在另一个中调用此 @Cacheable 函数 没有@Cacheable 的功能,缓存命中率不符合预期。
请看代码: http://www.devbeacon.com/d/cache1.zip
非常感谢!
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.
您的内部方法调用完全绕过了代理。 query2
也应该有 @Cacheable
。如果你不想那样,你需要改用 AspectJ 模式。