spring ehcache 캐 시 관리


 
 
 
 
<aop:config>
		<!--         -->
		<aop:advisor advice-ref="txAdvice" pointcut="execution(* *..*Service.*(..))" order="2"/>
		
		<!--         -->
		<aop:advisor advice-ref="cacheAdvice" pointcut="execution(* *..*Service.*(..))" order="0"/>
		
</aop:config>

 
<!--       -->
	<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
		<property name="cacheManager" ref="cacheManagerFactoryBean" />
	</bean>

	<!--        bean -->
	<bean id="cacheManagerFactoryBean" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
		<property name="configLocation" value="classpath:ehcache.xml" />
	</bean>

	<!--      key    -->
	<bean id="surveyparkKeyGenerator" class="com.surveypark.cache.SurveyparkKeyGenerator" />
	
	<!--      -->
	<cache:advice id="cacheAdvice" cache-manager="cacheManager" key-generator="surveyparkKeyGenerator">
		<cache:caching cache="surveyparkCache">
			<cache:cacheable method="get*" />
			<cache:cacheable method="load*" />
			<cache:cacheable method="find*" />
			
			<cache:cache-evict method="save*" all-entries="true" />
			<cache:cache-evict method="update*" all-entries="true"/>
			<cache:cache-evict method="delete*" all-entries="true"/>
			<cache:cache-evict method="clear*" all-entries="true"/>
			<cache:cache-evict method="toggle*" all-entries="true"/>
			<cache:cache-evict method="move*" all-entries="true"/>
			<cache:cache-evict method="batch*" all-entries="true"/>
			<cache:cache-evict method="execute*" all-entries="true"/>
		</cache:caching>
	</cache:advice>

 
ehcache.xml
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
    <diskStore path="java.io.tmpdir"/>
    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            maxElementsOnDisk="10000000"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />
    <cache name="surveyparkCache"
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            maxElementsOnDisk="10000000"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />
</ehcache>

 
 
public class SurveyparkKeyGenerator implements KeyGenerator{

	public Object generate(Object arg0, Method arg1, Object... arg2) {
		String className = arg0.getClass().getSimpleName();
		String mname = arg1.getName();
		String params = StringUtil.arr2Str(arg2);
		String key = className + "@" + arg0.hashCode() + "." + mname + "("+params+")"  ;
		return key;
	}

}

 
StringUtil.java
	public static String arr2Str(Object[] arr) {
		String temp = "" ;
		if(ValidateUtil.isValid(arr)){
			for(Object s : arr){
				temp = temp + s + "," ;
			}
			return temp.substring(0,temp.length() - 1);
		}
		return temp;
	}

 
 
 
 
 
 
 

좋은 웹페이지 즐겨찾기