天天看點

Jfinal整合EhCacheJfinal整合EhCache

Jfinal整合EhCache

Jfinal内部已經封裝了EhCahe,并作為Plugin存在,我們隻需開啟就行了。

//加載EhCache配置檔案
 EhCachePlugin ehCachePlugin=new EhCachePlugin(getClass().getClassLoader().getResource("ehcache.xml"));
 //啟動ehCachePlugin
 me.add(ehCachePlugin);
           

關于EhCache的配置檔案

http://blog.csdn.net/sinat_25926481/article/details/75315020

http://blog.csdn.net/sinat_25926481/article/details/75319917

Jfinal為EhCache封裝了操作類 CacheKit

/**
 * cacheName EhCache配置檔案中的<cache name="appIndexCache"/>
 * key 緩存對象的Key
 */
CacheKit.get(cacheName, key)
/**
 * cacheName EhCache配置檔案中的<cache name="appIndexCache"/>
 * key 緩存對象的Key
 * value 緩存對象
 */
CacheKit.put(cacheName, key, value);
           

可以使用CacheKit細粒化管理cache。

JFinal提供了更簡單的方式 AOP

提供了CacheInterceptor攔截器 緩存自動儲存更改

使用@Before(CacheInterceptor.class)

預設的cache name為ActionKey

提供@CacheName(“”) 自定義cache name

CacheInterceptor 緩存對象的key為 ActionKey加請求參數