May 14, 2021 JFinal manual
CacheKit is a cache operation tool class, and here's the sample code:
public void list() {The two most important methods in CacheKit are get (String cacheName, Object key) and put (String cacheName, Object key, Object value). T he get method is to take the data from the cache, and the put method is to put the data into the cache. T he parameter cacheName and ehcache .xml in the "blog" ... The value of the property value of the name corresponds to; the argument key refers to the key to which the value is taken; the argument value is the cached data.
List<Blog> blogList = CacheKit. get ("blog", "blogList");
if (blogList == null ) {
blogList = Blog. dao .find("select * from blog"); C acheKit. put ("blog", "blogList", blogList);
}
setAttr("blogList", blogList); render("blog.html");
}
The following code is an example of the CacheKit.get (String, String, IDataLoader) method overloaded in CacheKit:
public void list() {
List<Blog> blogList = CacheKit. get ("blog", "blogList", new IDataLoader(){
public Object load() {
return B log. dao .find("select * from blog");
}});
setAttr("blogList", blogList); render("blog.html");
}
The CacheKit.get method provides an IDataLoader interface in which the load() method is called only when the cache value does not exist. The specific operation flow of this method is: first of all, the cacheName-blog and key-blogList parameters to cache the data, if the data in the cache exists to return the data directly, there is no call IDataLoader.load() method to get the data.