Spring4中的java控制器缓存不工作
当我编写以下代码时,缓存不工作
@Cacheable("books")
@RequestMapping(method = RequestMethod.GET)
public String list(Model model) {
System.out.println("Retrieving products");
model.addAttribute("products", productDao.list());
return "products/list";
}
但是如果我写下面的代码,缓存就会工作
@Cacheable("books")
@RequestMapping(method = RequestMethod.GET)
public ModelAndView list() {
ModelAndView modelAndView = new ModelAndView("products/list");
System.out.println("Retrieving products");
modelAndView.addObject("products", productDao.list());
return modelAndView;
}
有人能告诉我为什么第一个代码没有缓存吗
# 1 楼答案
我想我找到了答案。 由于参数的原因,由于每次调用对象时对象可能不同,因此大多数情况下该值都不相等
因此,缓存会将其理解为不同的请求,不会带来缓存的值