Cache Service 를 적용해서 공통코드를 생성한다.
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"> <property name="cacheManager"> <bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:/spring/ehcache-default.xml"/> </bean> </property> </bean>
<ehcache> <diskStore path="user.dir/second"/> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" diskPersistent="true" diskExpiryThreadIntervalSeconds="120"/> <cache name="cvplCmmCd" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="360" timeToLiveSeconds="1000" overflowToDisk="false" diskPersistent="false" memoryStoreEvictionPolicy="LRU"> </cache> </ehcache>
@Resource(name="ehcache") Ehcache gCache ; Ehcache cache = gCache.getCacheManager().getCache("cvplCmmCd"); String chCode = ""; List cvplCmmnCdList = cvplCmmnCdService.selectCvplCmmnCdList(); List<CvplCmmnCdVO> mainCdList = new ArrayList<CvplCmmnCdVO>(); for (Iterator i = cvplCmmnCdList.iterator(); i.hasNext(); ) { CvplCmmnCdVO cvlpCmmnCdVO = (CvplCmmnCdVO)i.next(); . . . cache.put(new Element(chCode, mainCdList)); . . . }
@Resource(name="ehcache") Ehcache gCache ; Ehcache cache = gCache.getCacheManager().getCache("cvplCmmCd"); Element el = cache.get(key);