일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 7879
- Armeria
- hbase 저장공간 설정
- UnsupportedOperationException
- reids
- jsonMarshaller
- 애자일 싫타
- 개발 어렵당.ㅠ
- formik
- jar 배포
- 플루터
- nGinder
- Ingress Controller Fake
- OIDC
- 티스토리챌린지
- RedirectService
- 노드간 통신
- 월급루팡 일지
- fake jwt
- Loki 로그
- LPOS
- 핀포인트
- pinpoint 2.5.3
- intellij
- 오블완
- 논블록킹 성능
- pinpoint
- ㅉ때
- R2DBC Paging
- save/update
- Today
- Total
대머리개발자
스프링 Boot - ehcache 적용 본문
구글링을 하면 캐시 관련해서 수 많은 블로그가 나온다.
나한테 맞는(?) 쉬운 블로그를 찾아서 쑤욱 진행하면 된다. 요점만.. 간략하게!!. let's go
기본적인 캐시를 사용하겠다고 설정(?)하고 부트를 실행하면
@EnableCaching
Redis를 defualt CahceManager로 인식한다.
Using cache manager: org.springframework.data.redis.cache.RedisCacheManager
부트는 기본적으로 레디스 캐시를 설정한다고 한다.
기본적인 캐시 말고 우리는 ehcache를 사용할 거니깐. ehcache를 장착(?) 해야 한다.
implementation 'org.ehcache:ehcache:3.8.0'
implementation 'javax.cache:cache-api:1.0.0'
다시 부트를 실행하면 cacheManager가 ehcache로 장착을 되버렸다. 야호~
Using cache manager: org.springframework.cache.jcache.JCacheCacheManager
마지막으로 하나만 더 하면 끝이다. (ehcache.xml 작성과 위치 명시)
1. 작성 : 3.X 이상부터의 xml 설정이 2.X 하고는 완전 달라졌다. (자세한 설정은 구글링)
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://www.ehcache.org/v3' xmlns:jsr107="http://www.ehcache.org/v3/jsr107" xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
<cache-template name="defaultTemplate">
<expiry> <ttl unit="minutes">60</ttl></expiry>
<heap>300</heap></cache-template>
<cache alias="userCache" uses-template="defaultTemplate"/>
</config>
2. 위치 명시 : 부트에게 xml 위치를 알려줘야 한다.(application.yml)
cache: jcache: config: classpath:config/ehcache.xml
소스상에서 @Cacheable 걸어두면 잘 동작을 한다잉
@Cacheable(cacheNames="userCache", key="#account")
@CacheEvict(cacheNames="userCache", key="#account")
※※ 많은 블로그들이 ehcache를 사용함에 있어 아래 친구도 의존하라고 되어 있는데 안 해줘도 된다. 뭐든 의존하는 친구들을 왜 써야 하는지를 알아보면 좋다. 괜히 어플리케이션의 덩치만 커지고 추 후 유지보수 힘들어 진다.
implementation 'org.springframework.boot:spring-boot-starter-cache'
부트에서 제공하는 캐시 라이브러리로 간단하게 캐시를 사용할 수 있게 해주는 녀석이다. 하지만 난 ttl이라던지 부가적인 옵션이 더 필요하기 때문에 ehcache를 사용하는 것이다. 굳이 사용하지도 않는 친구를 의존하지 말자!!!
진짜 아무의 조건 없이 간단하게 사용해야 할때만 이용한다.(https://jeong-pro.tistory.com/170)
'개발이야기 > 자봐' 카테고리의 다른 글
JPA + queryDSL 적용기(?) (0) | 2022.04.08 |
---|---|
스프링 Boot Jar 배포 시 리소스 못 찾는 이슈 (0) | 2021.10.29 |
스프링 Boot - MessageSource 적용 (0) | 2021.08.28 |
스프링 Boot전환 (0) | 2021.07.16 |
스프링 Boot - Start (0) | 2021.07.09 |