Ehcache
2019. 6. 4. 10:37ㆍ[정리] 기능별 개념 정리/스프링 부트
EhCache 2.x 버전 + Spring boot
Ehcache 가 많이 사용됨에 따라 하나의 도메인으로 자리잡았고 EhCache 3.x 부터는 설정 방법이 바뀌게 되었다.
EhCache 3.x 버전 + Spring boot
resources/config/ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ehcache.org/v3"
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd">
<cache alias="myCache">
<key-type>java.lang.String</key-type>
<value-type>com.myproject.entity.AddressEntity</value-type>
<expiry>
<ttl unit="minutes">5</ttl>
</expiry>
<resources>
<heap unit="entries">10000</heap>
<offheap unit="MB">100</offheap>
</resources>
</cache>
</config>
EhCacheConfig
@EnableCaching
@Configuration
@EnableScheduling
public class EhCacheConfig {
@Bean
public JCacheManagerFactoryBean jCacheManagerFactoryBean() throws Exception{
JCacheManagerFactoryBean jCacheManagerFactoryBean = new JCacheManagerFactoryBean();
jCacheManagerFactoryBean.setCacheManagerUri(new ClassPathResource("config/ehcache.xml").getURI());
return jCacheManagerFactoryBean;
}
@Bean
public JCacheCacheManager jCacheCacheManager(JCacheManagerFactoryBean jCacheManagerFactoryBean) {
JCacheCacheManager jCacheCacheManager = new JCacheCacheManager();
jCacheCacheManager.setCacheManager(jCacheManagerFactoryBean.getObject());
return jCacheCacheManager;
}
}
Cacheable
public Class MyClass{
@Autowired
private MemberRepository memberRepository;
@Cacheable(
value = "myCache",
key="#memberEntity.id")
public Address getAddress(MemberEntity memberEntity){
log.info("getAddress was called.");
AddressEntity addressEntity = memberRepository.findById(memberEntity.getId()).get();
return addressEntity;
}
}
Ehcache 는 eviction 전략을 지원하지 않는다.
https://github.com/ehcache/ehcache3/issues/2134
https://stackoverflow.com/questions/44790690/how-does-ehcache3-handle-eviction-when-cache-is-full
https://groups.google.com/forum/#!topic/ehcache-users/uuF71EUijKE
'[정리] 기능별 개념 정리 > 스프링 부트' 카테고리의 다른 글
스프링 부트 Request 데이터 validation (0) | 2019.09.09 |
---|---|
필터, 인터셉터, AOP (0) | 2019.05.28 |
스프링 부트 Cache (0) | 2019.05.27 |
PSA (추상화 계층) (0) | 2019.05.01 |
스프링 부트의 Mock (0) | 2019.04.28 |