콘텐츠로 이동
Bluetape4k 문서1.11

Cache 전략과 생태계 경로

최신 안정판 Bluetape4k 1.11.0 릴리스 기준

전략miss/쓰기 owner원본 저장소 호출
cache-asidecallercaller가 직접 조회·저장
read-throughCacheLoader/MapLoadercache miss가 loader를 호출
write-throughCacheWriter/MapWritercache write 완료 전에 writer 호출
write-behindwriter queuecache write 뒤 비동기로 원본 반영

RedissonNearCache.put()과 memoizer의 RMap.putIfAbsent()는 Redis cache를 갱신할 뿐입니다. database table을 호출하는 writer가 없으므로 persistence write-through가 아닙니다.

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를 별도로 정합니다.

examples/redisson-demoMapLoader, 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의 cache 장은 JdbcCacheRepository, EntityMapLoader, EntityMapWriter를 연결해 repository와 cache 경계를 보여 줍니다. Hibernate와 Exposed 중 어느 persistence 모델을 선택하든 transaction commit 전후 invalidation 규칙은 별도로 필요합니다.

bluetape4k-workshop은 서비스 수준 예제로 이어지는 경로입니다. workshop 코드가 이 매뉴얼의 전략 이름과 다르면 실제 loader/writer 호출을 기준으로 판단합니다.