【问题标题】:Spring + Ehcache - can @Cacheable be used to cache the output of a jsp viewSpring + Ehcache - 可以使用@Cacheable 来缓存jsp视图的输出
【发布时间】:2012-05-02 06:06:46
【问题描述】:

基本上,是否可以这样做:

@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";
}

当我尝试这个时,视图被缓存了,但是从缓存中返回的只是jsp的纯内容,而不是简单的jsp视图渲染逻辑完成后的jsp视图。我在 spring 3.0.7,所以仍然使用 ehcache-spring-annotations (http://code.google.com/p/ehcache-spring-annotations)

【问题讨论】:

    标签: spring ehcache


    【解决方案1】:

    @Cacheable 的工作原理是根据所有输入参数简单地形成一个键,并将返回值放在该键下。

    因此它不会存储已处理的视图 - 它只会存储视图名称。

    通常,您会为此使用浏览器缓存而不是服务器端缓存。而且由于渲染视图应该比生成内容消耗更少,因此您可以将@Cacheable 放在服务方法上。

    【讨论】:

    • 好吧,我没有深入研究细节,但在这种情况下,cacheable 是存储 jsp 的普通输出,而不是处理后的输出。但是,这仍然回答了我的问题,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 2018-02-07
    • 2020-01-14
    • 2021-02-21
    • 2012-12-12
    • 1970-01-01
    相关资源
    最近更新 更多