public class CacheTest {
List<String> list = new ArrayList<String>();
public CacheTest(){
for(int i=0; i<5; i++){
list.add(String.valueOf(i*i));
}
}
@Cacheable(value="CacheExample", key="#index")
public String getMap(int index){
System.out.println("CacheTest................");
return list.get(index);
}
}
CacheTest.getMap()์ ํธ์ถํ์ ๊ฒฝ์ฐ ํค์ ํด๋นํ๋ ๊ฐ์ด ์์ผ๋ฉด ์ฝ์๋ก ์ฐํ์ง ์๋๊ฒ ์บ์ฑ์ ํ๋๊ฒ ์๋๊ฐ์?
XML ์ค์ ์ ์๋์ ๊ฐ์ด ๊ธฐ๋ณธ๋ง ์ค์ ํด๋ดค์ต๋๋ค.
<cache:annotation-driven />
<bean id="cacheManager"
class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="default"/>
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="CacheExample" />
</set>
</property>
</bean>
Ehcache๋ฅผ ์ฌ์ฉํ๊ธฐ ์ ์ 3.1์์ ์ง์ํ๋ ๊ธฐ๋ฅ์ผ๋ก๋ ์ถฉ๋ถํ์ง ๊ฒํ ํด๋ณด๊ณ ๋์
ํด๋ณด๋ ค๊ณ ํ๋๋ฐ
์ค์ ์ด๋ ์ฝ๋ฉ์ด ์๋ชป๋์๋์ง ์บ์ฑ์ด ์ด๋ค์ง์ง ์๋๋ฏํ๋ค์.
--
Google ๊ทธ๋ฃน์ค 'Korea Spring User Group' ๊ทธ๋ฃน์ ๊ฐ์ ํ์ผ๋ฏ๋ก ๋ณธ ๋ฉ์ผ์ด ์ ์ก๋์์ต๋๋ค.
์ด ๊ทธ๋ฃน์ ๊ฒ์ํ๋ ค๋ฉด ks...@googlegroups.com(์ผ)๋ก ์ด๋ฉ์ผ์ ๋ณด๋ด์ธ์.
๊ทธ๋ฃน์์ ํํดํ๋ ค๋ฉด ksug+uns...@googlegroups.com๋ก ์ด๋ฉ์ผ์ ๋ณด๋ด์ฃผ์ธ์.
๋ ๋ง์ ์ต์ ์ ๋ณด๋ ค๋ฉด http://groups.google.com/group/ksug?hl=ko์์ ๊ทธ๋ฃน์ ๋ฐฉ๋ฌธํ์ธ์.
ํธ์ถ ์์ค๋ Spring MVC ์ปจํธ๋กค๋ฌ์์ DI(Autowired) ๋ฐ์์ ํด๋น ๋ฉ์๋๋ฅผ ์ ์ ์ผ๋ก ํธ์ถํ์ต๋๋ค.
public class XXXController {
@Autowired
private CacheTest cache;
@RequestMapping(value = "/list")
public String methodXX(Model model){
logger.error(cache.getMap(2));
}
์ ์ฝ๋๋ก ํธ์ถ ์ ์บ์ฑ์ ํ๊ณ ์ ํ๋ getMap() ํจ์์ ์ฝ์๋ฌธ์ฅ์ด ์ฐํ๊ณ
์ปจํธ๋กค๋ฌ์์ ์ฐ์ ๋ก๊ทธ๋ ์ฐํ๋ค์.
sts์์ spring template project๋ก 'MVC' ํ๋ก์ ํธ๋ฅผ ์์ฑ์ ํด์ ์ฌ์ฉํ๋ค ๋ณด๋
application-context.xml๊ณผ servlet-context.xml ์ ๋ถ์ฐํ์ฌ ์ค์ ํ๊ฒ ๋์์ต๋๋ค.
(๋ค๋ฅธ ๋ฐฉ๋ฒ์ด ์์ผ์๋ฉด ๋ต๋ณ ๋ถํ๋๋ฆฝ๋๋ค.)
ํน์ ๋ค๋ฅธ ๋ถ๋ค์ ์ํด ๊ณต์ ํด๋ด
๋๋ค.
root-context.xml ์์ ๋น์ ๋ฑ๋กํ๊ณ
<!-- Cache -->
<bean id="cacheManager"
class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="default"/>
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="CacheExample" />
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="CacheTime" />
</set>
</property>
</bean>
servlet-context.xml ์์ ๋น ์ค์บ์ ์ก์์คฌ์ต๋๋ค.
<!-- Cache -->
<cache:annotation-driven />
์ด๋ก์ ์คํ๋ง ์ค์ ์ ๋๋๊ณ ๋ฐ๋ก ํธ์ถํด์ ์ฌ์ฉํ๋ฉด ์ ์ฉ๋์์ต๋๋ค.
On 5์30์ผ, ์คํ8์42๋ถ, Sanghyuk Jung <bene...@gmail.com> wrote:
> ๋ค, ํ๋ฒ AopUtils.isProxy(cache)๋ก proxy๊ฐ ์ ์ฉ๋์๋์ง ํ์ธํด๋ณด๋ฉด ์ข์๋ฏํฉ๋๋ค.
>
> ์๋์ด ์๋ค๋ฉด component-scan์ ์ธ๋ถ๋ถ์ ํ๋ฒ ์ดํด๋ด์ผํ ๋ฏํ๋ค์
>
> 2012๋ 5์ 30์ผ ์คํ 5:36, ๋์ด๋ฝ๋ฆฌ <nife...@gmail.com>๋์ ๋ง: