如何缓存每个HTTP会话和超时的GSP片段



我使用的是Grails 2.2.0 GSP的异步include:

<g:include action="asyncAction" />

问题:如何缓存由"asyncAction"生成的内容a)一定的时间,b)每个用户的会话?不写自定义标签


我强迫客户端缓存"asyncAction",但Chrome/Firefox每次都请求它:

response.addHeader("Cache-Control", "max-age=1600, public")

用Grails的"cache"插件提供的<cache:block>封装了这个包含——让它在每个应用程序中永远缓存。

<g:include action="asyncAction" />

调用asyncAction操作并将输出添加到页面。所以如果你安装了缓存插件,你应该给这个动作添加@Cacheable注释

@Cacheable('someCache') 
def asyncAction() {
}

则在Config.groovy中指定名为someCache的缓存的超时时间

someCache {
    name 'someCache'
    timeToIdleSeconds 60 * 60  // item will be removed if not requested at least this often
    timeToLiveSeconds 60 * 120 // item will be always be removed after this period
}

最新更新