Spring + Ehcache - can @Cacheable be used to cache the output of a jsp view

牧云@^-^@ 提交于 2019-12-24 03:11:05

问题


Basically, is it possible to do this:

@Cacheable(cacheName="default")
@RequestMapping("getContent/{name}")
public String getContentByNameHandler(@PathVariable String name, Model model) {

    ContentService contentService = domainService.getContentService();

    model.addAttribute("model",contentService.getContentByName(name));

    return RESOURCE_FOLDER + "content";
}

When I try this, the view is cached, but the only the plain content of the jsp is returned from the cache, not the jsp view after the simple jsp view rendering logic has completed. I'm on spring 3.0.7, so still using the ehcache-spring-annotations (http://code.google.com/p/ehcache-spring-annotations)


回答1:


@Cacheable works by simply forming a key based on all input parameters, and putting the return value under that key.

So it won't store the processed view - it will simply store the view name.

Normally, you'd use browser caching for that instead of server-side caching. And since rendering the view is supposed to be less consuming than generating the content, you'd put @Cacheable on the service method.



来源:https://stackoverflow.com/questions/10404365/spring-ehcache-can-cacheable-be-used-to-cache-the-output-of-a-jsp-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!