【发布时间】:2015-11-18 07:11:13
【问题描述】:
我在 Spring Boot 应用程序中使用 Simple Spring Memcached (SSM)。我是 memcached 的新手,我正在努力理解事物。
下面的代码
@RestController
public class TestController {
@RequestMapping(value = "/checkend", method = RequestMethod.GET)
@Cacheable(value="defaultCache")
public String checkInteger(int Id){
RandomClass r = new RandomClass();
System.out.println("cache miss...");
return r.testCache("random");
}
}
public class RandomClass {
@Cacheable(value = "defaultCache")
public String testCache(String randomId){
System.out.println("came here ");
return "done1";
}
}
休息后调用 ex: localhost:9000/checkend?Id=7 memcached stores (7 作为键,“done1”作为值)并且会在进行相同的 rest 调用时从缓存中检索..(注意:它不会缓存 RandomClass 中方法“testCache”的结果“为什么是这样?”)甚至对于
@RequestMapping(value = "/checkend", method = RequestMethod.GET)
public String checkInteger(int Id){
RandomClass r = new RandomClass();
System.out.println("cache miss...");
return r.testCache("random");
}
}
public class RandomClass {
@Cacheable(value = "defaultCache")
public String testCache(String randomId){
System.out.println("came here ");
return "done1";
}
}
它不会使用给定的输入缓存“testCache”方法。有什么理由不缓存这种情况下的RandomClass的方法吗?
【问题讨论】:
标签: spring-boot memcached spring-cache simple-spring-memcached