如果数据变化的频率很低,就可以通过缓存技术来优化网站的性能,比如jfinal整合的ehcache的使用,只需要两个设置,1 ehcache.xml 配置,2在插件配置configPlugin里面加一句me.add(new EhCachePlugin());
首先在插件配置中初始化
public void configPlugin(Plugins me) {
//配置缓存插件
me.add(new EhCachePlugin());
}
配置ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="false" monitoring="autodetect"
dynamicConfig="true">
<diskStore path="java.io.tmpdir"/>
<cache name="sampleCache1"
maxEntriesLocalHeap="10000"
maxEntriesLocalDisk="1000"
eternal="false"
overflowToDisk="true"
diskSpoolBufferSizeMB="20"
timeToIdleSeconds="300"
timeToLiveSeconds="100"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off"
/>
</ehcache>
详细配置参考说明
http://blog.youkuaiyun.com/mlitsn/article/details/1909192
代码调用
public class IndexController extends Controller{
public void index(){
Map<String, Object> indexMap= CacheKit.get("sampleCache1", "index");
if (indexMap== null) {
System.err.println("缓存不存在");
indexMap=new HashMap<String, Object>();
indexMap.put("test", Test.dao.find("select * from test"));
CacheKit.put("sampleCache1", "index", indexMap);
}else{
System.err.println("已经缓存");
}
setAttr("indexMap", indexMap);
renderJson();
render("index.html");
}
}
如果广大网友觉得这篇文章有用,可以用 666导航网 收藏起来,方便随时查看
如果广大网友觉得这篇文章有用,可以用
666导航网 收藏起来,方便随时查看