kok202
Ehcache

2019. 6. 4. 10:37[정리] 기능별 개념 정리/스프링 부트

EhCache 2.x 버전 + Spring boot

https://jaehun2841.github.io/2018/11/07/2018-11-04-ehcache-config-for-springboot/#ehcachexml-%EC%9E%91%EC%84%B1-ehcache-%EC%84%A4%EC%A0%95%ED%8C%8C%EC%9D%BC

 

EHCache 설정방법 (Spring Boot) | Carrey`s 기술블로그

EHCache 설정하기 설정 순서는 아래와 같다. Maven Dependency 설정 Ehcache.xml 작성 (ehcache 설정파일) @EnableCaching 설정 Maven Dependency 설정 123456789 org.springframework.boot spring-boot-starter-cache net.sf.ehcache ehcache 2.10.6 Ehcache.xml 작성 (ehcache 설정파일) 1234567891011121314

jaehun2841.github.io

 

Ehcache 가 많이 사용됨에 따라 하나의 도메인으로 자리잡았고 EhCache 3.x 부터는 설정 방법이 바뀌게 되었다.

https://stackoverflow.com/questions/44341553/cannot-access-net-sf-ehcache-cachemanager-class-file-for-net-sf-ehcache-cachema

 

cannot access net.sf.ehcache.CacheManager, class file for net.sf.ehcache.CacheManager not found

I have been implementing some caching in my project using EhCache. I have added following dependencies to my pom.xml

 

 

 

 

 

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