[英]Controller cache in Spring4 is not working
當我編寫以下代碼時,緩存不起作用
@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;
}
有人可以說出為什么第一個代碼不緩存嗎?
我想我找到了答案。 由於存在該參數,由於每次調用對象都可以不同,因此大多數情況下該值將不相等。
因此,緩存會將其理解為不同的請求,並且不會帶來緩存的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.