Cache 전략과 생태계 경로
최신 안정판 Bluetape4k 1.11.0 릴리스 기준
이름보다 데이터 경로를 본다
섹션 제목: “이름보다 데이터 경로를 본다”| 전략 | miss/쓰기 owner | 원본 저장소 호출 |
|---|---|---|
| cache-aside | caller | caller가 직접 조회·저장 |
| read-through | CacheLoader/MapLoader | cache miss가 loader를 호출 |
| write-through | CacheWriter/MapWriter | cache write 완료 전에 writer 호출 |
| write-behind | writer queue | cache write 뒤 비동기로 원본 반영 |
RedissonNearCache.put()과 memoizer의 RMap.putIfAbsent()는 Redis cache를 갱신할 뿐입니다. database table을 호출하는 writer가 없으므로 persistence write-through가 아닙니다.
Cache-aside 기본형
섹션 제목: “Cache-aside 기본형”suspend fun findProduct(id: String): Product { products.get(id)?.let { return it } return repository.findById(id).also { loaded -> products.put(id, loaded) }}첫 요청은 DB에서 읽고 cache를 채웁니다. update에서는 DB commit과 cache invalidate 순서, 실패 뒤 stale window를 별도로 정합니다.
Redisson loader와 writer로 확장
섹션 제목: “Redisson loader와 writer로 확장”examples/redisson-demo는 MapLoader, MapWriter와 async 대응 API로 read-through, write-through, write-behind를 보여 줍니다. 이 예제에서는 loader/writer가 실제 repository를 호출하므로 cache-aside와 구분할 수 있습니다.
write-behind는 응답 latency를 줄일 수 있지만 process crash, queue overflow, ordering과 retry에 따라 데이터 손실·재정렬 위험이 생깁니다. 원본 데이터의 유일한 쓰기 경로로 채택하기 전에 durability 요구를 검증합니다.
모듈 선택 경로
섹션 제목: “모듈 선택 경로”- cache-core: local provider, JCache, memoizer와 공통 Near Cache 계약부터 배웁니다.
- redisson: Redisson codec, distributed map, lock, topic과 coroutine bridge를 확장합니다.
- Hibernate: entity lifecycle과 second-level cache 경계를 다룹니다.
- Spring Boot Hibernate Lettuce: Spring/Hibernate cache wiring을 확인합니다.
- redisson-demo: loader/writer가 있는 실행 예제로 전략 차이를 검증합니다.
Exposed와 workshop
섹션 제목: “Exposed와 workshop”exposed-workshop의 cache 장은 JdbcCacheRepository, EntityMapLoader, EntityMapWriter를 연결해 repository와 cache 경계를 보여 줍니다. Hibernate와 Exposed 중 어느 persistence 모델을 선택하든 transaction commit 전후 invalidation 규칙은 별도로 필요합니다.
bluetape4k-workshop은 서비스 수준 예제로 이어지는 경로입니다. workshop 코드가 이 매뉴얼의 전략 이름과 다르면 실제 loader/writer 호출을 기준으로 판단합니다.