- 浏览: 133885 次
- 性别:
- 来自: 北京
文章分类
最新评论
一、 配置文件ehcache.xml
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskPersistent="true"/>
<cache name="resourceCache"
maxElementsInMemory="10000"
eternal="false"
overflowToDisk="true"/>
</ehcache>
二、 配置Bean
<beans:bean id="resourceCache" class="com.wanmei.system.security.cache.ResourceCache">
<beans:property name="cache">
<beans:bean class="org.springframework.cache.ehcache.EhCacheFactoryBean" autowire="byName">
<beans:property name="cacheManager" ref="cacheManager"/>
<beans:property name="cacheName" value="resourceCache"/>
</beans:bean>
</beans:property>
</beans:bean>
三、 对象
public class ResourceCache {
private Cache cache;
public void setCache(Cache cache) {
this.cache = cache;
}
public Cache getCache() {
return this.cache;
}
public Object getAuthorityFromCache(String resString) {
Element element = null;
try {
element = cache.get(resString);
} catch (CacheException cacheException) {
throw new DataRetrievalFailureException("Cache failure: " + cacheException.getMessage(), cacheException);
}
if (element == null) {
return null;
} else {
return element.getValue();
}
}
public void putAuthorityInCache(Object obj) {
Element element = new Element(key, obj);
if (logger.isDebugEnabled()) {
logger.debug("Cache put: " + element.getKey());
}
this.cache.put(element);
}
public void removeAuthorityFromCache(String resString) {
this.cache.remove(resString);
}
private List<String> getResourcesByType(String type) {
List resources;
List<String> resclist = new ArrayList<String>();
try {
resources = this.cache.getKeys();
} catch (IllegalStateException e) {
throw new IllegalStateException(e.getMessage(), e);
} catch (CacheException e) {
throw new UnsupportedOperationException(e.getMessage(), e);
}
for (Iterator iter = resources.iterator(); iter.hasNext();) {
String resString = (String) iter.next();
ResourceDetails resourceDetails = getAuthorityFromCache(resString);
if (resourceDetails != null && resourceDetails.getResourceType().equals(type)) {
resclist.add(resString);
}
}
return resclist;
}
}
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskPersistent="true"/>
<cache name="resourceCache"
maxElementsInMemory="10000"
eternal="false"
overflowToDisk="true"/>
</ehcache>
二、 配置Bean
<beans:bean id="resourceCache" class="com.wanmei.system.security.cache.ResourceCache">
<beans:property name="cache">
<beans:bean class="org.springframework.cache.ehcache.EhCacheFactoryBean" autowire="byName">
<beans:property name="cacheManager" ref="cacheManager"/>
<beans:property name="cacheName" value="resourceCache"/>
</beans:bean>
</beans:property>
</beans:bean>
三、 对象
public class ResourceCache {
private Cache cache;
public void setCache(Cache cache) {
this.cache = cache;
}
public Cache getCache() {
return this.cache;
}
public Object getAuthorityFromCache(String resString) {
Element element = null;
try {
element = cache.get(resString);
} catch (CacheException cacheException) {
throw new DataRetrievalFailureException("Cache failure: " + cacheException.getMessage(), cacheException);
}
if (element == null) {
return null;
} else {
return element.getValue();
}
}
public void putAuthorityInCache(Object obj) {
Element element = new Element(key, obj);
if (logger.isDebugEnabled()) {
logger.debug("Cache put: " + element.getKey());
}
this.cache.put(element);
}
public void removeAuthorityFromCache(String resString) {
this.cache.remove(resString);
}
private List<String> getResourcesByType(String type) {
List resources;
List<String> resclist = new ArrayList<String>();
try {
resources = this.cache.getKeys();
} catch (IllegalStateException e) {
throw new IllegalStateException(e.getMessage(), e);
} catch (CacheException e) {
throw new UnsupportedOperationException(e.getMessage(), e);
}
for (Iterator iter = resources.iterator(); iter.hasNext();) {
String resString = (String) iter.next();
ResourceDetails resourceDetails = getAuthorityFromCache(resString);
if (resourceDetails != null && resourceDetails.getResourceType().equals(type)) {
resclist.add(resString);
}
}
return resclist;
}
}
发表评论
-
使用memcached进行并发控制(转)
2015-12-29 14:39 830版权声明:本文为博主 ... -
Lock和Synchronized的不同
2014-10-24 15:46 734在 Java 中线程的状态可以分为:新建(New),运行状 ... -
ClassLoader加载流程
2014-04-16 09:59 575[b]当运行一个程序的时候,JVM启动, 运行bootstar ... -
springmvc请求接收参数的几种方法(转载)
2014-04-14 13:37 1479通过@PathVariabl注解获取路径中传递参数 JAVA ... -
JDK里的设计模式
2014-03-10 09:52 573适配器模式: 用来把一个接口转化成另一个接口。 java ... -
include与jsp:include区别
2014-02-28 15:03 548在jsp中include有两种形式,分别是 <%@ i ... -
DBCP的配置参数
2014-02-25 15:51 710tomcatde DHCP的配置 <Resource d ... -
java 时间处理的工具类(转)
2014-01-27 15:13 614import java.text.ParseException ... -
log4j
2014-01-17 13:56 336public Logger m_log = null; ... -
关于java Date和时区的问题
2013-12-18 11:55 809java2平台为我们提供了丰富的日期时间API。如java.u ... -
hessian异常总结
2013-12-12 17:53 1213版本不兼容 com.caucho.hessian.io.Hes ... -
java异常
2013-09-06 12:01 523java.sql.SQLException: Incorrec ... -
汉字转码的java实现
2013-08-05 17:26 971package common; import java.ut ... -
验证邮件的有效性
2013-07-30 14:25 1100public static boolean checkEma ... -
优化Servlet配置
2013-04-09 10:31 612[b] 以往每添加一个Servlet就要在web. ... -
纯hessian的部署(转)
2012-11-06 17:44 798Web 服务是通过在 Web 服务器上部署 Servlet 来 ... -
struts2上传文件活动文件名、类型
2012-05-16 08:45 898public class FileUpload { ... -
struts2乱码
2012-05-14 17:36 0Struts2.1.6 StrutsPrepareAndExe ... -
解决struts2过滤器冲突问题
2012-04-27 13:40 0struts2使用FilterDispatcher进行url过 ... -
cron表达式
2012-03-14 15:02 825所在组的定时任务用的quartz,是我第一个用的,今天有同事用 ...
相关推荐
EhCache使用详解,HIBERNATE缓冲
Ehcache使用: CacheManager主要的缓存管理类,一般一个应用为一个实例,如下 CacheManager.create();也可以使用new CacheManager的方式创建 默认的配置文件为ehcache.xml文件,也可以使用不同的配置: ...
每次需要shiro做权限控制, Realm的授权方法就会被调用, 查询数据库重新完成授权! 问题: 性能开销比较大 解决: 对用户授权,只进行一次 查询,查询后,将用户授权信息放入缓存中,以后需要授权时,直接从缓存...
Ehcache API,页面缓存,分布式缓存。
包括配置、原理讲解及使用示例。简洁的文档
EHCache使用手册,Hibernate默认的缓存
此为ehcache的使用以及集群的使用,具体需要两台机子,将ehcache 的hostName替换相应的ip即可
NULL 博文链接:https://huntt.iteye.com/blog/2058937
为了写这个例子我从网上找了好几天的资料,终于看到的效果,里面有非分布式的例子,有分布式例子(包括 rmi,jgroups tcp/udp 的分布式调用方式)。
ehcache使用例子,maven项目。
EHCache使用SimplePageCachingFilter类实现Filter缓存。该类继承自CachingFilter,有默认产生cache key的calculateKey()方法,该方法使用HTTP请求的URI和查询条件来组成key。也可以自己实现一个Filter,同样继承...
hibernate二级缓存的使用,快速使用手册,一学就会。Ehcache是一个快速的、轻量级的、易于使用的、进程内的缓存。它支持read-only 和read/write 缓存,内存和磁盘缓存。是一个非常轻量级的缓存实现
ehcache配置使用详解,里面有具体的例子
java EHCache使用,Hibernate缓存 收集整理
EhCache 是一个纯 Java 的进程内缓存框架,具有快速、精干等特点,是 Hibernate 中默认的 CacheProvider。这篇文章主要介绍了SpringBoot中使用Ehcache的相关知识,需要的朋友可以参考下
cache、ehcache等缓存使用,实现存对象读对象等等
ehcache3-samples, 关于使用 Ehcache 3,一些示例/教程 Ehcache示例这里知识库包含有关 Ehcache 3用法的示例和教程。示例'basic'演示 Ehcache 3的基本配置和用法'集群'- 演示如何在Terracotta服务器上使用分布式缓存...
1.解压缩到目录下,复制ehcache-monitor-kit-1.0.0\lib\ehcache-probe-1.0.0.jar包到application的web-inf/lib目录下 2.将以下配置copy的ehcache.xml文件的ehcache标签中,注:上述链接中说的配置少写了个probe包名...
Spring与ehcache结合使用,本地缓存的实现