专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

五十二、6.3 CacheInterceptor

文章永久连接:https://tech.souyunku.com/8296

CacheInterceptor 可以将 action 所需数据全部缓存起来,下次请求到来时如果 cache 存在则 直接使用数据并 render,而不会去调用 action。此用法可使 action 完全不受 cache 相关代码所 污染,即插即用,以下是示例代码:

@Before(CacheInterceptor. class)
public void list() {
List blogList = Blog. dao.find(“select * from blog”); User user = User. dao.findById(getParaToInt()); setAttr(“blogList”, blogList);
setAttr(“user”, user); render(“blog.html”);
}

上例中的用法将使用 actionKey 作为 cacheName,在使用之前需要在 ehcache.xml 中配置以 actionKey 命名的 cache 如:,注意 actionKey 作为 cacheName 配置 时斜杠”/”不能省略。此外 CacheInterceptor 还可以与 CacheName 注解配合使用,以此来取代默认的 actionKey 作为actionName,以下是示例代码:

@Before(CacheInterceptor. class)
@CacheName(“blogList”)
public void list() {
List blogList = Blog. dao.find(“select * from blog”); setAttr(“blogList”, blogList);
render(“blog.html”);
}

以上用法需要在 ehcache.xml 中配置名为 blogList 的 cache 如:

干货推荐

未经允许不得转载:搜云库技术团队 » 五十二、6.3 CacheInterceptor

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们