Skip to content

Caffeine Cache 확장#119

Merged
chooh1010 merged 9 commits into
mainfrom
feat/cache-expansion
May 13, 2026
Merged

Caffeine Cache 확장#119
chooh1010 merged 9 commits into
mainfrom
feat/cache-expansion

Conversation

@chooh1010

@chooh1010 chooh1010 commented May 13, 2026

Copy link
Copy Markdown
Member

✨ 이슈 번호: #114

완료된 작업

  • CacheConfig: per-cache Caffeine 설정 (boardFirstPage/postDetail/commentFirstPage)
  • 통합 CacheEvictEvent + @TransactionalEventListener(AFTER_COMMIT) 패턴
  • 게시판 첫 페이지 캐시 (board ID 키, 좋아요 비evict, 캐시 스탬피드 방지)
  • 게시글 상세 캐시 (개인 반응 매번 fresh 합성, viewCount/likeCount TTL 허용)
  • 댓글 첫 페이지 캐시 (기존 → 통합 이벤트로 마이그레이션)
  • 조회수 메모리 카운터 (ConcurrentHashMap + LongAdder + @scheduled 30초 flush)
  • replace 패턴으로 flush 동시성 안전 처리
  • TransactionTemplate으로 self-invocation 문제 해결
  • CacheTests 14개 + ViewCountServiceTest 7개 + CacheEvictListenerTest 4개

주요 설계 결정

  • likeCount/viewCount는 TTL 만료까지 stale 허용 (evict하지 않음)
  • 캐시에는 공통 데이터만 저장, 개인화(likedByMe)는 매 요청 합성
  • Scale Out 시 Redis로 전환 예정

chooh1010 and others added 9 commits May 13, 2026 21:53
- Create CacheConfig with per-cache settings (boardFirstPage, postDetail, commentFirstPage)
- Add @Profile("!nocache") guard to prevent conflict with nocache profile
- Replace CommentCacheEvictEvent with generic CacheEvictEvent(cacheName, key)
- Replace CommentCacheEvictListener with generic CacheEvictListener
- Add fallbackExecution=true for non-transactional context safety
- Migrate CommentService to use generic cache eviction event
- Update all related tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove likedByMe/dislikedByMe fields from PostListItemResponse
- Remove withReactions() method and reaction merge logic from getPostPage()
- Simplify BoardController.getBoard() by removing unused principal/cookie params
- Update JPQL constructor expression to match new 9-param signature
- Update PostServiceTest to match new method signatures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Cache board listing page 0 using Caffeine (key: boardId, TTL: 5min)
- Stampede prevention via cache.get(key, Callable)
- Evict on post create/update/delete (member and guest)
- Capture boardId before delete to avoid accessing deleted entity
- likeCount staleness accepted until TTL expiry (documented)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CacheConfig bean now manages per-cache settings directly.
SPRING_CACHE_* environment variables are no longer effective.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Cache PostResponse in postDetail cache (key: postId, TTL: 30min)
- Merge personal reactions (likedByMe/dislikedByMe) fresh on every request
- Add PostResponse.withReactions() for reaction merging
- Evict postDetail on post update/delete and comment create/delete
- viewCount/likeCount stale until TTL expiry (acceptable)
- Remove TODO comments from CacheConfig

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace per-request DB UPDATE with ConcurrentHashMap<Long, LongAdder>
memory counter. Accumulated counts are flushed to DB every 30 seconds
via @scheduled. Uses replace pattern for safe concurrent flush, per-entry
@transactional for failure isolation, and @PreDestroy for shutdown flush.

Add board first page and post detail cache tests to CacheTests (14 total).
Add ViewCountServiceTest with 7 tests including concurrency verification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tion

@transactional on flushSingle() was bypassed because flushViewCounts()
called it within the same class (Spring proxy self-invocation). Replaced
with TransactionTemplate.executeWithoutResult() which works without proxy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The only TransactionTemplate bean was readOnlyTx (read-only=true),
causing "Connection is read-only" error when ViewCountService tried
to flush view counts. Added a separate txTemplate bean with default
read-write mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chooh1010 chooh1010 linked an issue May 13, 2026 that may be closed by this pull request
9 tasks
@chooh1010 chooh1010 self-assigned this May 13, 2026
@chooh1010 chooh1010 added the feat add new features label May 13, 2026
@sonarqubecloud

Copy link
Copy Markdown

@chooh1010 chooh1010 merged commit 5358283 into main May 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat add new features

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Caffeine Cache 확장

1 participant