May 14, 2021 JFinal manual
CacheInterceptor can cache all the data needed for action, and if cache exists the next time the cache arrives, use the data directly and render without calling action. This usage allows action to be completely free from cache-related code, plug-and-play, and here's the sample code:
@Before(CacheInterceptor. class )The usage in the example above will use actionKey as cacheName, and you need to configure the cache named actionKey in ehcache.xml before using it, such as: N ote that the slash "/" cannot be omitted when actionKey is configured as cacheName. In addition, CacheInterceptor can be used with CacheName annotations instead of the default actionKey as actionName, and here's the sample code:
public void list () {
List<Blog> blogList = Blog. dao .find("select * from blog"); U ser user = User. dao .findById(getParaToInt()); setAttr("blogList", blogList);
setAttr("user", user); render("blog.html");
}
@Before(CacheInterceptor. class )
@CacheName("blogList")
public void list () {
List<Blog> blogList = Blog. dao .find("select * from blog"); setAttr("blogList", blogList);
render("blog.html");
}
The above usage needs to be .xml cache named blogList in the ehcache file, such as: >。