반응형
Java Config를 이용하는 경우에 해당합니다. (xml 설정은 1년전에 안쓰기로 버렸기 때문에... 본 포스트에는 내용이 없습니다.)
4.1.0으로 넘어오면서 override되는 메소드가 두개정도 추가되었습니다만..
필수로 구현해야 하는건 아닌거 같더군요.
1. 설정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | @Configuration @EnableCaching public class CachingConfig implements CachingConfigurer { @Bean (destroyMethod= "shutdown" ) public net.sf.ehcache.CacheManager ehCacheManager() { CacheConfiguration staticConfig = new CacheConfiguration(); staticConfig.setName( "StaticConfig" ); // 캐시 이름 staticConfig.setMemoryStoreEvictionPolicy( "LRU" ); // 메모리에 저장되는 방식을 결정 staticConfig.setMaxEntriesLocalHeap( 100 ); // 최대로 캐싱할 수 있는 Entries의 수 staticConfig.setTimeToIdleSeconds( 3600 ); staticConfig.setTimeToLiveSeconds( 3600 ); net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration(); config.addCache(staticConfig); return net.sf.ehcache.CacheManager.newInstance(config); } @Bean @Override public CacheManager cacheManager() { return new EhCacheCacheManager(ehCacheManager()); } @Bean @Override public KeyGenerator keyGenerator() { return new SimpleKeyGenerator(); } @Override public CacheResolver cacheResolver() { // TODO Auto-generated method stub return null ; } @Override public CacheErrorHandler errorHandler() { // TODO Auto-generated method stub return null ; } |
2. 사용
1 2 3 4 5 6 7 8 9 | @Cacheable (value= "StaticConfig" , key= "#configNum" ) // StaticConfig라는 캐시에 configNum을 기준으로 캐싱한다. public Object selectStaticConfig( int configNum) { // TODO } @CacheEvict (value= "StaticConfig" ) // StaticConfig에 캐싱되어 있던 내용을 초기화한다. public Object selectStaticConfigInitCache( int configNum) { // TODO } |
매우 간단합니다.
반응형
'개발 > Spring Framework' 카테고리의 다른 글
[Spring Framework] ModelAttribute Annotation (0) | 2016.06.10 |
---|---|
[Spring Framework] ReloadedResourceBundleMessageSource의 활용 (0) | 2016.06.10 |
[Spring Framework] AOP @Around (0) | 2016.06.10 |
[Spring Data Commons] ChaniedTransactionManager (0) | 2016.06.10 |
[Spring Framework] @ControllerAdvice를 이용한 에러핸들링 (0) | 2016.06.10 |