`
xiashenghai
  • 浏览: 23151 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ehcache备忘

阅读更多

 

很多东西长时间不用就会忘记,然后再回过头来再去找,很浪费时间。还是在写下来比较好。

 

ehcache的配置文件:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd">

	<diskStore path="java.io.tmpdir"/>
	
    <defaultCache
            maxElementsInMemory="10000"
            eternal="true"
            overflowToDisk="false"
            timeToIdleSeconds="0"
            timeToLiveSeconds="0"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"/>

    <cache name="activity.rule"
           maxElementsInMemory="100"
           eternal="true"
           overflowToDisk="false"/>
    <cache name="organ.organDept"
           maxElementsInMemory="500"
           eternal="true"
           overflowToDisk="false"/>

</ehcache>
 

其中<cache>标签定义的就是要用的配置。

 

定义好了之后需要在spring配置文件中定义下一,一边容器启动后能创建cache的实例:

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
		<description>EHCache的Manager</description>
		<property name="configLocation">
			<value>classpath:config/ehcache.xml</value>
		</property>
</bean>

	<bean id = "organDeptService" class = "com.cpic.p17.base.service.impl.OrganDeptServiceImpl" parent = "abstractOrganService">
		<property name="sequence"><value>INT_ORG_SEQ</value></property>
		
		<property name="propertyCompanyFilePath"><value>/js/dynamic/propertycomany.js</value></property>
		<property name="propertyBranchFilePath"><value>/js/dynamic/propertybranch.js</value></property>
		
		<property name="lifeCompanyFilePath"><value>/js/dynamic/lifecompany.js</value></property>
		<property name="lifeBrachFilePath"><value>/js/dynamic/lifebranch.js</value></property>
		
		<property name="propertyB2cFilePath"><value>/js/dynamic/propertyb2c.js</value></property>
		<property name="lifeB2cFilePath"><value>/js/dynamic/lifeb2c.js</value></property>
		
		<property name="variableNamePropertyCompany"><value>propertycomany</value></property>
		<property name="variableNamePropertyBranch"><value>propertybranch</value></property>
		
		<property name="variableNameLifeCompany"><value>lifecompany</value></property>
		<property name="variableNameLifeBranch"><value>lifebranch</value></property>
		
		<property name="variablePropertyB2c"><value>propertyc2b</value></property>
		<property name="variableLifeB2c"><value>lifec2b</value></property>
		
		<property name="applicationCacheService" ref="applicationCacheService"></property>
		<property name="areaAssService" ref="areaAssService"></property>
		<property name="parametersValueService" ref="parametersValueService" ></property>
		<property name="organDao" ref="organDao"></property>
		<property name="cacheManager" ref="cacheManager"></property>
	</bean>

 代码很简单,一看就明白,organDeptService中那么的属性是项目中用的,与本文无关,也懒的删了,不多说了,接下来看看ServiceImpl中怎么处理的。

 

private Cache organCache;

public void setCacheManager(CacheManager cacheManager) {
		organCache = cacheManager.getCache("organ.organDept");
	}

public List getBranchOrganChildList(Long organId) {
		if(organId != null && !"".equals(organId)) {
			Element children = organCache.get(organId.toString());
			if(children == null) {
				OrganDept organDept = getOrganDetpById(organId);
				if(organDept != null) {
					List childrenList = getChildOrgan(organDept.getOrganId());
					OrganDept child = null;
					List list = new ArrayList();
					for(int i = 0;i < childrenList.size();i++) {
						child = (OrganDept) childrenList.get(i);
						KeyValue keyValue = new KeyValue();
						keyValue.setKey(child.getOrganId());
						keyValue.setValue(child.getPartyFullname());
						list.add(keyValue);
					}
					Element element = new Element(organId.toString(),list);
					organCache.put(element);
					return list;
				}else {
					return Collections.EMPTY_LIST;
				}
			}else {
				return (List)children.getValue();
			}
		} else {
			return Collections.EMPTY_LIST;
		}
	}

 用法就这么简单。那么大段的代码是包含了业务逻辑,只需要看看cache是怎么存对象,和怎么取对象就行了。

分享到:
评论

相关推荐

    ehcache监控工具ehcache-monitor-kit-1.0.3

    1.解压缩到目录下,复制ehcache-monitor-kit-1.0.0\lib\ehcache-probe-1.0.0.jar包到application的web-inf/lib目录下 2.将以下配置copy的ehcache.xml文件的ehcache标签中,注:上述链接中说的配置少写了个probe包名...

    ehcache.xsd_ehcache.xml代码提示.rar

    【标题解析】:“ehcache.xsd_ehcache.xml代码提示.rar”这个标题表明这是一个与Ehcache缓存系统相关的资源包,主要目的是为Ehcache的配置文件ehcache.xml提供代码提示功能。Ehcache是一个广泛使用的开源Java缓存...

    ehcache.jar及源码

    Ehcache是一个广泛使用的开源Java缓存库,它为应用程序提供了高效的内存管理和数据缓存功能。Ehcache的核心目标是提高应用性能,通过将频繁访问的数据存储在内存中,减少对数据库的依赖,从而降低系统负载。这次我们...

    ehcache

    **Ehcache 知识详解** Ehcache 是一个开源的、高性能的缓存解决方案,广泛应用于Java应用程序中,尤其在提升系统性能和减少数据库负载方面表现突出。它支持内存和磁盘存储,并且可以与Java持久层框架如Hibernate、...

    hibernate+ehcache

    【标题】:“Hibernate + Ehcache 整合使用详解” 【描述】:“Hibernate 是一款流行的 Java 持久层框架,而 Ehcache 是一个高效的分布式内存缓存系统。将两者结合,能够极大地提升应用的性能,减少数据库的负载,...

    mybatis ehcache 1.0 ehcache.xsd 提示文件

    本篇文章将详细探讨MyBatis与Ehcache的集成以及`ehcache.xsd`和`ehcache.xml`这两个配置文件在其中的作用。 首先,Ehcache是一个开源的、高性能的Java缓存库,它能够极大地减少对数据库的访问,提高应用程序的响应...

    ehcache2.6.5.rar

    Ehcache是一个开源的Java缓存库,广泛用于提高应用程序的性能和响应速度,通过存储经常访问的数据在内存中,避免了频繁的数据库查询。它最初由Tomi Triebel开发,现在是Terracotta公司的产品。在版本2.6.5中,...

    ehcache资料(包含ehcache jar包)

    **Ehcache** 是一个广泛使用的Java缓存库,它为应用程序提供了本地内存缓存功能,以提高数据访问速度和减少数据库负载。Ehcache在处理高并发和大数据量的场景下表现出色,尤其适用于那些频繁读取但不经常修改的数据...

    Ehcache(一): Spring + Ehcache开场白

    Ehcache是一款高性能、易用且广泛应用于Java环境中的分布式缓存系统,它极大地提高了应用程序的性能和响应速度。在Spring框架中集成Ehcache,能够实现数据的快速访问,减轻数据库的压力,优化整体系统架构。本文将...

    ehcache-3.9.9-API文档-中英对照版.zip

    赠送jar包:ehcache-3.9.9.jar; 赠送原API文档:ehcache-3.9.9-javadoc.jar; 赠送源代码:ehcache-3.9.9-sources.jar; 赠送Maven依赖信息文件:ehcache-3.9.9.pom; 包含翻译后的API文档:ehcache-3.9.9-javadoc-...

    Ehcache 3(ehcache-clustered-3.8.1-kit.zip)

    Ehcache 3 是一个广泛使用的开源Java缓存解决方案,特别是在需要高性能、低延迟的数据存储和检索场景下。Ehcache 3 提供了丰富的功能,包括本地内存缓存、磁盘持久化、多线程支持以及在分布式环境中实现集群共享缓存...

    ehcache的配置参数详解

    hibernate ehcache.xml 配置详解

    Ehcache_Hello

    **Ehcache简介** Ehcache是一款开源的Java缓存框架,它被广泛应用于提高应用程序性能,通过存储数据副本以减少对数据库的访问。Ehcache最初由Tomi Tirro设计,现在是Terracotta公司的产品,是Java世界中常用的二级...

    ehcache开发工具包

    EhCache是一款高效、易用且功能强大的Java缓存库,它被广泛应用于各种Java应用程序中,以提高数据访问速度并降低数据库负载。EhCache的核心特性包括内存和磁盘存储、缓存分区、过期策略以及缓存同步等。在Java开发中...

    ehcache-terracotta代码配置

    Ehcache是一个流行的Java缓存库,用于提高应用程序性能,减少对数据库的访问。当与Terracotta结合使用时,Ehcache可以实现分布式缓存,使得多台服务器上的应用可以共享同一份缓存数据,从而构建高可用的集群环境。在...

    Spring+Ehcache集成

    **Spring与Ehcache集成详解** 在现代Java应用开发中,缓存技术是提升系统性能的关键环节。Ehcache作为一款流行的开源缓存解决方案,因其轻量级、高性能和易于集成的特点,常被广泛应用于Spring框架中。本篇文章将...

    ehcache-2.10.6.jar

    ehcache-2.10.6.jar ehcache jar包供各位开发人员 学习、交流,切勿用于商业用途。

    Ehcache 简单的监控

    Ehcache是一个开源的、高性能的缓存解决方案,广泛应用于Java应用程序中,以提高数据访问的速度和效率。本文将深入探讨Ehcache的简单监控,帮助开发者更好地理解其工作原理和性能状态。 首先,了解Ehcache的核心...

    ehcache-3.8.1.zip

    Ehcache是一个开源的Java缓存库,广泛用于提高应用程序性能,通过存储数据副本来减少对数据库的访问。在3.8.1版本中,它提供了丰富的功能和优化,以支持高并发环境下的高效缓存操作。以下是关于Ehcache 3.8.1的知识...

    ehcache项目缓存技术

    Ehcache是Java平台上的一个开源、高性能的分布式缓存系统,它在处理大量用户访问主页或频繁操作某些数据时,能显著提升系统的响应速度和效率。本篇文章将深入探讨Ehcache项目的缓存技术及其应用。 一、Ehcache简介...

Global site tag (gtag.js) - Google Analytics