CacheInterceptor
CacheInterceptor can cache all the data required by the action. If the cache exists when the next request comes, the data will be used directly and rendered without calling the action. This usage can make the action completely free from cache-related code pollution, plug and play, the following is the sample code:
public void list() {
List<Blog> blogList = Blog.dao.find("select * from blog"); User user = User.dao.findById(getParaToInt()); setAttr("blogList", blogList);
setAttr( "user", user); render("blog.html");
}
The usage in the above example will use actionKey as cacheName, which needs to be configured in ehcache.xml before use The cache named with actionKey is such as: <cache name="/blog/list" ...>. Note that the slash "/" cannot be omitted when actionKey is configured as cacheName. In addition, CacheInterceptor can also be used with the CacheName annotation to replace the default actionKey as actionName. The following is a sample code:
@CacheName("blogList" )
public void list() {
List<Blog> blogList = Blog.dao.find("select * from blog"); setAttr("blogList", blogList);
render("blog. html");
}
The above usage requires configuring the cache named blogList in ehcache.xml, such as: <cache name="blogList" …>.