캐시 제거

This commit is contained in:
jinia91
2022-05-02 01:17:32 +09:00
parent f7476e96ef
commit 5c4aaace00

View File

@@ -1,95 +1,95 @@
package myblog.blog.infra.config; //package myblog.blog.infra.config;
//
import net.sf.ehcache.Cache; //import net.sf.ehcache.Cache;
import net.sf.ehcache.config.CacheConfiguration; //import net.sf.ehcache.config.CacheConfiguration;
import org.springframework.cache.ehcache.EhCacheCacheManager; //import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean; //import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
//
import java.util.Objects; //import java.util.Objects;
//
/* ///*
- 캐시 인터페이스 설정 // - 캐시 인터페이스 설정
*/ //*/
//@Configuration //@Configuration
public class CacheConfig { //public class CacheConfig {
//
/* // /*
- EhCache 팩터리 빈 등록 // - EhCache 팩터리 빈 등록
*/ // */
@Bean // @Bean
public EhCacheManagerFactoryBean cacheManagerFactoryBean(){ // public EhCacheManagerFactoryBean cacheManagerFactoryBean(){
return new EhCacheManagerFactoryBean(); // return new EhCacheManagerFactoryBean();
} // }
//
/* // /*
- Ehcache 등록 // - Ehcache 등록
- 메모리 <-> 성능 트레이드 오프를 고려할때 1)레이아웃 캐싱과 2)매핑 비용이 비싼 rss정도만 캐시처리 // - 메모리 <-> 성능 트레이드 오프를 고려할때 1)레이아웃 캐싱과 2)매핑 비용이 비싼 rss정도만 캐시처리
- 캐시 폐기는 6시간마다 // - 캐시 폐기는 6시간마다
*/ // */
@Bean // @Bean
public EhCacheCacheManager ehCacheCacheManager(){ // public EhCacheCacheManager ehCacheCacheManager(){
//
/* // /*
1. 레이아웃에 필요한 단건 dto 캐시 // 1. 레이아웃에 필요한 단건 dto 캐시
- key 0 : 레이아웃 카테고리 // - key 0 : 레이아웃 카테고리
- key 1 : 메인화면 인기 아티클 // - key 1 : 메인화면 인기 아티클
*/ // */
CacheConfiguration layoutCacheConfiguration = new CacheConfiguration() // CacheConfiguration layoutCacheConfiguration = new CacheConfiguration()
.eternal(false) // .eternal(false)
.timeToIdleSeconds(3600) // .timeToIdleSeconds(3600)
.timeToLiveSeconds(3600) // .timeToLiveSeconds(3600)
.maxEntriesLocalHeap(5) // .maxEntriesLocalHeap(5)
.memoryStoreEvictionPolicy("LRU") // .memoryStoreEvictionPolicy("LRU")
.name("layoutCaching"); // .name("layoutCaching");
//
Cache layoutCache = new net.sf.ehcache.Cache(layoutCacheConfiguration); // Cache layoutCache = new net.sf.ehcache.Cache(layoutCacheConfiguration);
Objects.requireNonNull(cacheManagerFactoryBean().getObject()).addCache(layoutCache); // Objects.requireNonNull(cacheManagerFactoryBean().getObject()).addCache(layoutCache);
//
// 2. 레이아웃에 필요한 동적 리스트반환 메서드용 캐시 // // 2. 레이아웃에 필요한 동적 리스트반환 메서드용 캐시
CacheConfiguration recentArticleCacheConfiguration = new CacheConfiguration() // CacheConfiguration recentArticleCacheConfiguration = new CacheConfiguration()
.eternal(false) // .eternal(false)
.timeToIdleSeconds(3600) // .timeToIdleSeconds(3600)
.timeToLiveSeconds(3600) // .timeToLiveSeconds(3600)
.maxEntriesLocalHeap(100) // .maxEntriesLocalHeap(100)
.memoryStoreEvictionPolicy("LRU") // .memoryStoreEvictionPolicy("LRU")
.name("layoutRecentArticleCaching"); // .name("layoutRecentArticleCaching");
//
Cache recentArticleCache = new net.sf.ehcache.Cache(recentArticleCacheConfiguration); // Cache recentArticleCache = new net.sf.ehcache.Cache(recentArticleCacheConfiguration);
Objects.requireNonNull(cacheManagerFactoryBean().getObject()).addCache(recentArticleCache); // Objects.requireNonNull(cacheManagerFactoryBean().getObject()).addCache(recentArticleCache);
//
// 3. 레이아웃에 필요한 리스트 반환 메서드용 캐시, 유지보수를 위해 분리 // // 3. 레이아웃에 필요한 리스트 반환 메서드용 캐시, 유지보수를 위해 분리
CacheConfiguration recentCommentCacheConfiguration = new CacheConfiguration() // CacheConfiguration recentCommentCacheConfiguration = new CacheConfiguration()
.eternal(false) // .eternal(false)
.timeToIdleSeconds(3600) // .timeToIdleSeconds(3600)
.timeToLiveSeconds(3600) // .timeToLiveSeconds(3600)
.maxEntriesLocalHeap(5) // .maxEntriesLocalHeap(5)
.memoryStoreEvictionPolicy("LRU") // .memoryStoreEvictionPolicy("LRU")
.name("layoutRecentCommentCaching"); // .name("layoutRecentCommentCaching");
//
Cache recentCommentCache = new net.sf.ehcache.Cache(recentCommentCacheConfiguration); // Cache recentCommentCache = new net.sf.ehcache.Cache(recentCommentCacheConfiguration);
Objects.requireNonNull(cacheManagerFactoryBean().getObject()).addCache(recentCommentCache); // Objects.requireNonNull(cacheManagerFactoryBean().getObject()).addCache(recentCommentCache);
//
/* // /*
- 4. seo 캐시 // - 4. seo 캐시
- key 0 : rss // - key 0 : rss
- key 1 : sitemap // - key 1 : sitemap
- key 2 : // - key 2 :
*/ // */
CacheConfiguration rssConfiguration = new CacheConfiguration() // CacheConfiguration rssConfiguration = new CacheConfiguration()
.eternal(false) // .eternal(false)
.timeToIdleSeconds(21600) // .timeToIdleSeconds(21600)
.timeToLiveSeconds(21600) // .timeToLiveSeconds(21600)
.maxEntriesLocalHeap(5) // .maxEntriesLocalHeap(5)
.memoryStoreEvictionPolicy("LRU") // .memoryStoreEvictionPolicy("LRU")
.name("seoCaching"); // .name("seoCaching");
//
Cache rssCache = new net.sf.ehcache.Cache(rssConfiguration); // Cache rssCache = new net.sf.ehcache.Cache(rssConfiguration);
Objects.requireNonNull(cacheManagerFactoryBean().getObject()).addCache(rssCache); // Objects.requireNonNull(cacheManagerFactoryBean().getObject()).addCache(rssCache);
//
return new EhCacheCacheManager(Objects.requireNonNull(cacheManagerFactoryBean().getObject())); // return new EhCacheCacheManager(Objects.requireNonNull(cacheManagerFactoryBean().getObject()));
//
} // }
//
} //}