场景
使用 spring cache 框架时 服务类内部方法调用并不触发缓存动作
演示
[[@Service](http://my.oschina.net/service)](http://my.oschina.net/service)
public class CacheTestService {
@Cacheable(value = "test_cache", key = "'method'")
public String method() {
System.out.println("method");
return method1(1) + "_" +
method2(2) + "_" +
method3(3) + "_" +
method4(4)
;
}
@Cacheable(value = "test_cache", key = "'method'+#i")
public String method1(int i) {
System.out.println("method1");
return "method1_" + i;
}
@Cacheable(value = "test_cache", key = "'method'+#i")
protected String method2(int i) {
System.out.println("method2");
return "method2_" + i;
}
@Cacheable(value = "test_cache", key = "'method'+#i")
String method3(int i) {
System.out.println("method3");
return "method3