-root-Context.xml(주 설정파일)에 ehcache와 cacheManager을 둘 다 등록해야 한다. 다음은 간단한 예다.


<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">

<property name="cacheManager" ref="ehcache"></property>

</bean>

<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">

<property name="configLocation" value="classpath:ehcache.xml"></property> 

</bean>


설정파일 간단한 예제는 다음과 같다.


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

xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true">

<cache name="someString"

     maxBytesLocalHeap="10M"

     eternal="false"

     timeToIdleSeconds="600"

     overflowToDisk="false"

     maxElementsOnDisk="1000"      

     memoryStoreEvictionPolicy="LRU"/>

</ehcache>


-메소드에다가 @Cacheable 이렇게 쓰려면 <cache:annotation-driven/>도 등록


-Controller에는 @Cacheable을 하면 안된다. Service에다가 하자.


-@Cacheable의 key 값에 대한 간단한 예제는 다음과 같다.

@Cacheable(value="someString", key="#someString.concat(#someClass.var1).concat(#someClass.var2).concat(#someClass.val3)")


Posted by 타다키치
,