기본정보#

  • 홈페이지 : http://ehcache.sourceforge.net/
  • 최신버전 : 2009년01월17일 현재 1.5.0이 최신버전이지만 1.6.0-beta2 까지 릴리즈되어 있다.
  • 설치시 필요한 파일(파일버전은 릴리즈에 따라 다를수 있다.)
    • jsr107cache-1.0.jar
    • backport-util-concurrent-3.0.jar
    • ehcache-1.5.0.jar
    • ehcache.xml

설정하기#

ehcache.xml#

<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
	<diskStore path="java.io.tmpdir" />

	<!-- 기본적인 캐시설정 -->
	<!--defaultCache 
		maxElementsInMemory="50000" 
		eternal="false"
		timeToIdleSeconds="300" 
		timeToLiveSeconds="600" 
		overflowToDisk="true"
		diskPersistent="false" 
		diskExpiryThreadIntervalSeconds="120"
		memoryStoreEvictionPolicy="LRU">
	</defaultCache-->

	<!-- 분산캐싱을 위한 캐시설정 -->
	<defaultCache 
		maxElementsInMemory="50000" 
		eternal="false"
		timeToIdleSeconds="300" 
		timeToLiveSeconds="600" 
		overflowToDisk="true"
		diskPersistent="false" 
		diskExpiryThreadIntervalSeconds="120"
		memoryStoreEvictionPolicy="LRU">
		<cacheEventListenerFactory
			class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
	</defaultCache>

	<cacheManagerPeerProviderFactory
		class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
		properties="
			peerDiscovery=automatic, 
			multicastGroupAddress=230.0.0.1,
            multicastGroupPort=3209, 
            timeToLive=32" />
	<cacheManagerPeerListenerFactory
		class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
		properties="
			port=3208, 
			socketTimeoutMillis=2000" />
</ehcache>

Spring Bean설정#

<bean id="ehcache" 
	class="org.springframework.cache.ehcache.EhCacheFactoryBean"
	p:cacheName="">
	<property name="cacheManager">
		<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
			p:configLocation="classpath:ehcache.xml" />
	</property>
</bean>

로그#

웹애플리케이션 시작시 초기 로그#

2009-01-17 20:51:32,500 DEBUG - ConfigurationFactory.parseConfiguration(145) | Configuring ehcache from InputStream
2009-01-17 20:51:32,515 DEBUG - DiskStoreConfiguration.translatePath(98) | Disk Store Path: C:\DOCUME~1\fromm0\LOCALS~1\Temp\
2009-01-17 20:51:32,515 DEBUG - ConfigurationHelper.createCacheManagerEventListener(300) | No CacheManagerEventListenerFactory class specified. Skipping...
2009-01-17 20:51:32,531 DEBUG - PropertyUtil.extractAndLogProperty(56) | Value found for hostName: null
2009-01-17 20:51:32,531 DEBUG - PropertyUtil.extractAndLogProperty(56) | Value found for port: 3208
2009-01-17 20:51:32,531 DEBUG - PropertyUtil.extractAndLogProperty(56) | Value found for remoteObjectPort: null
2009-01-17 20:51:32,531 DEBUG - PropertyUtil.extractAndLogProperty(56) | Value found for socketTimeoutMillis: 2000
2009-01-17 20:51:32,531 DEBUG - PropertyUtil.extractAndLogProperty(56) | Value found for peerDiscovery: automatic
2009-01-17 20:51:32,531 DEBUG - PropertyUtil.extractAndLogProperty(56) | Value found for multicastGroupAddress: 230.0.0.1
2009-01-17 20:51:32,546 DEBUG - PropertyUtil.extractAndLogProperty(56) | Value found for multicastGroupPort: 3209
2009-01-17 20:51:32,546 DEBUG - PropertyUtil.extractAndLogProperty(56) | Value found for timeToLive: 32
2009-01-17 20:51:32,562 DEBUG - PropertyUtil.parseProperties(88) | propertiesString is null.
2009-01-17 20:51:32,562 DEBUG - ConfigurationHelper.createBootstrapCacheLoader(180) | No BootstrapCacheLoaderFactory class specified. Skipping...
2009-01-17 20:51:32,562 DEBUG - ConfigurationHelper.createCacheLoader(205) | No CacheLoaderFactory class specified. Skipping...
2009-01-17 20:51:32,562 DEBUG - ConfigurationHelper.createCacheExceptionHandler(230) | No CacheExceptionHandlerFactory class specified. Skipping...
2009-01-17 20:51:33,593 DEBUG - RMICacheManagerPeerListener.init(211) | 0 RMICachePeers bound in registry for RMI listener
2009-01-17 20:51:33,609 DEBUG - DiskStoreConfiguration.translatePath(98) | Disk Store Path: C:\DOCUME~1\fromm0\LOCALS~1\Temp\
2009-01-17 20:51:33,609 DEBUG - DiskStore.initialiseFiles(201) | Deleting data file .data
2009-01-17 20:51:33,640 DEBUG - MemoryStore.<init>(73) | Initialized net.sf.ehcache.store.LruMemoryStore for 
2009-01-17 20:51:33,640 DEBUG - LruMemoryStore.loadMapInstance(71) |  Cache: Using SpoolingLinkedHashMap implementation
2009-01-17 20:51:33,640 DEBUG - Cache.initialise(557) | Initialised cache: 
2009-01-17 20:51:33,640 DEBUG - RMICacheManagerPeerListener.notifyCacheAdded(494) | Adding  to RMI listener
2009-01-17 20:51:33,640 DEBUG - RMICacheManagerPeerListener.notifyCacheAdded(523) | 0 RMICachePeers bound in registry for RMI listener

캐시처리#

캐시에서 가져오기#

메서드 #

friendList = (List<Account>) cache.get("getFriendList").getValue();

캐시에 존재하지 않을 경우#

2009-01-17 20:54:02,843 DEBUG - MemoryStore.get(138) | Cache: MemoryStore miss for getFriendList
2009-01-17 20:54:02,859 DEBUG - Cache.get(808) |  cache - Miss

캐시에 존재할 경우#

2009-01-17 20:55:42,390 DEBUG - MemoryStore.get(135) | Cache: MemoryStore hit for getFriendList

캐시에 데이터 저장하기#

메서드#

friendList = dao.getFriendList(account);
Element element = new Element("getFriendList", friendList);
cache.put(element);

참고사이트#

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-5) was last changed on 17-Jan-2009 21:16 by DongGukLee