标签:ehcache 缓存 return cache private 开源 static jeesite1.2
Shiro缓存
参考资料
数据缓存
spring-context-shiro.xml定义了缓存管理器:
<bean id="shiroCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManager" ref="cacheManager"/>
</bean>
该管理器在spring-context.xml进行了声明:
<!-- 缓存配置 -->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:${ehcache.configFile}" />
</bean>
ehcache.configFile对应的值为:
ehcache.configFile=cache/ehcache-local.xml
其内容为:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache updateCheck="false" name="defaultCache">
<diskStore path="../temp/jeesite/ehcache" />
<!-- 默认缓存配置. 自动失效:最后一次访问时间间隔300秒失效,若没有访问过自创建时间600秒失效。-->
<defaultCache maxEntriesLocalHeap="1000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600"
overflowToDisk="true" statistics="true"/>
<!-- 系统缓存 -->
<cache name="sysCache" maxEntriesLocalHeap="1000" eternal="true" overflowToDisk="true" statistics="true"/>
<!-- 用户缓存 -->
<cache name="userCache" maxEntriesLocalHeap="1000" eternal="true" overflowToDisk="true" statistics="true"/>
<!-- 集团缓存 -->
<cache name="corpCache" maxEntriesLocalHeap="1000" eternal="true" overflowToDisk="true" statistics="true"/>
<!-- 内容管理模块缓存 -->
<cache name="cmsCache" maxEntriesLocalHeap="1000" eternal="true" overflowToDisk="true" statistics="true"/>
<!-- 工作流模块缓存 -->
<cache name="actCache" maxEntriesLocalHeap="100" eternal="true" overflowToDisk="true" statistics="true"/>
<!-- 简单页面缓存 -->
<cache name="pageCachingFilter" maxEntriesLocalHeap="1000" eternal="false" timeToIdleSeconds="120"
timeToLiveSeconds="120" overflowToDisk="true" memoryStoreEvictionPolicy="LFU" statistics="true"/>
<!-- 系统活动会话缓存 -->
<cache name="activeSessionsCache" maxEntriesLocalHeap="10000" eternal="true" overflowToDisk="true"
diskPersistent="true" diskExpiryThreadIntervalSeconds="600" statistics="true"/>
</ehcache>
比如在登录过程中用到的CacheUtils就是借助ehcache做缓存管理:
public class CacheUtils {
private static Logger logger = LoggerFactory.getLogger(CacheUtils.class);
private static CacheManager cacheManager = SpringContextHolder.getBean(CacheManager.class);
private static final String SYS_CACHE = "sysCache";
/**
* 获取SYS_CACHE缓存
* @param key
* @return
*/
public static Object get(String key) {
return get(SYS_CACHE, key);
}
/**
* 获得一个Cache,没有则显示日志。
* @param cacheName
* @return
*/
private static Cache<String, Object> getCache(String cacheName){
Cache<String, Object> cache = cacheManager.getCache(cacheName);
if (cache == null){
throw new RuntimeException("当前系统中没有定义“"+cacheName+"”这个缓存。");
}
return cache;
}
}
Session缓存
遇到时补充
标签:ehcache,缓存,return,cache,private,开源,static,jeesite1.2 来源: https://www.cnblogs.com/sk-lqbzblogs/p/16386322.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。