Spring + Ehcache-@Cacheable可以用于缓存jsp视图的输出 [英] Spring + Ehcache - can @Cacheable be used to cache the output of a jsp view

查看:65
本文介绍了Spring + Ehcache-@Cacheable可以用于缓存jsp视图的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上可以这样做:

@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)

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)

推荐答案

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

@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.

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

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.

这篇关于Spring + Ehcache-@Cacheable可以用于缓存jsp视图的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆