jfinal ehcache缓存的使用

如果数据变化的频率很低,就可以通过缓存技术来优化网站的性能,比如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导航网   收藏起来,方便随时查看
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值