天天看点

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加请求参数