[feat] Spring Cache(Caffeine) 도입 — 화이트리스트 기반 Strict + after-commit 이벤트 무효화#137
Merged
[feat] Spring Cache(Caffeine) 도입 — 화이트리스트 기반 Strict + after-commit 이벤트 무효화#137
Conversation
- - CacheConfig: Caffeine 캐시, 캐시별 정책(최대치/TTL/recordStats) - Strict 모드: 미등록 캐시 이름 사용 시 fail-fast - Post 관련 캐시 무효화 이벤트/리스너 기본 구조 추가
- - PostService: 수정/삭제/비활성화 시 캐시 무효화 이벤트 발행 - PostImageService: 이미지 변경 시 관련 캐시 키 정밀 무효화 신호 전파 - PostImageRepository: 서비스 변경 흐름에 맞춘 시그니처 보완
|
✅ 테스트 통과! |
src/main/java/kr/co/pinup/cache/listener/PostCacheInvalidationListener.java
Show resolved
Hide resolved
src/main/java/kr/co/pinup/cache/listener/PostCacheInvalidationListener.java
Outdated
Show resolved
Hide resolved
var 제거하고 Cache 등 명시 타입으로 변경 evictIfPresent 헬퍼 추가하여 중복 getCache/null 체크 정리 이벤트/변수 의미 있는 이름으로 리네이밍
whoamixzerone
approved these changes
Oct 31, 2025
Collaborator
whoamixzerone
left a comment
There was a problem hiding this comment.
고생하셨습니다.
단순히 캐시만 등록하는게 아닌 다른 규칙들도 고민하고 적용한 것이 느껴지네요 👏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
요약
@TransactionalEventListener(phase = AFTER_COMMIT)로 커밋 후 정밀evict수행.post:detail,post:images(CacheNames.POST_DETAIL/POST_IMAGES).작업 내용
CaffeineCacheManager커스터마이징setCacheNames(...)로 허용 캐시명 화이트리스트 적용(동적 생성 차단)AppCacheProps(yml 바인딩)로 주입,recordStats()활성화PostCacheEvent(Kind: UPDATED/DISABLED/DELETED, postId, detailChanged, imagesChanged)PostCacheInvalidationListenerUPDATED:detailChanged→post:detail만 evict,imagesChanged→post:images만 evictDISABLED:post:detailevictDELETED:post:detail,post:images모두 evict참고 사항
hit/miss/put/evict/size지표 기반으로 TTL/size 조정(초기값 예: TTL 60s / size 1k).spring.cache.type=caffeinespring.cache.app.defaults/caches로 per-cachettlSec,maximumSize설정관련 이슈