Skip to content

fix: 빈 배열 Redis 캐싱 방지#167

Merged
kangcheolung merged 1 commit intodevelopfrom
feature/166
Mar 3, 2026
Merged

fix: 빈 배열 Redis 캐싱 방지#167
kangcheolung merged 1 commit intodevelopfrom
feature/166

Conversation

@kangcheolung
Copy link
Copy Markdown
Member

@kangcheolung kangcheolung commented Mar 3, 2026

🔍️ 작업 내용

  • Closes #
    빈 배열 Redis 캐싱 방지

✨ 상세 설명

운영 스웨거에서 브랜드, 카테고리 조회시 빈배열 반환할 경우가 많았습니다. 이를 해결하기 위해 아래처럼 수정했습니다.

  • cached != null 체크를 cached != null && !cached.isEmpty()로 변경
  • DB 조회 결과가 빈 배열인 경우 Redis에 저장하지 않도록 수정
  • 카테고리/브랜드 전체 조회 API에서 빈 배열이 영구 캐싱되던 문제 해결

🛠️ 추후 리팩토링 및 고도화 계획

📸 스크린샷 (선택)

💬 리뷰 요구사항

Summary by CodeRabbit

릴리스 노트

  • Bug Fixes

    • 브랜드 및 카테고리 조회 시 빈 응답에 대한 처리 개선
  • Chores

    • 브랜드 및 카테고리 서비스 안정성 강화를 위한 로깅 기능 추가
    • 조회 캐싱 로직 최적화로 불필요한 캐시 저장 제거

- cached != null 체크를 cached != null && !cached.isEmpty()로 변경
- DB 조회 결과가 빈 배열인 경우 Redis에 저장하지 않도록 수정
- 카테고리/브랜드 전체 조회 API에서 빈 배열이 영구 캐싱되던 문제 해결

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 3, 2026

Walkthrough

BrandService와 CategoryService에 SLF4J 로깅을 추가하고, 캐시 검증 로직을 강화했습니다. 캐시된 데이터의 비어있음 여부를 확인하는 조건(cached != null && !cached.isEmpty())을 추가하고, DB 조회 후 빈 결과에 대해 경고 로그를 남기고 조기 반환하는 가드 조건을 도입했습니다.

Changes

Cohort / File(s) Summary
Redis 캐시 및 로깅 개선
src/main/java/com/ongil/backend/domain/brand/service/BrandService.java, src/main/java/com/ongil/backend/domain/category/service/CategoryService.java
@slf4j 어노테이션으로 로깅 지원 추가, 캐시 히트 조건을 cached != null && !cached.isEmpty()로 강화, 빈 응답에 대해 경고 로그 후 조기 반환하는 가드 추가 (각 파일 +8/-1)

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Possibly related PRs

  • [Fix]브랜드, 카테고리 Redis 캐싱  #44: 동일한 BrandService/CategoryService의 캐시 처리 로직을 개선하는 PR으로, 기존에 도입된 캐싱 로직에 대해 로깅과 비어있음 검증 조건을 추가합니다.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경사항의 핵심을 정확히 반영하고 있습니다. 빈 배열의 Redis 캐싱 방지라는 주요 목적이 명확하게 드러나 있습니다.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/166

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/java/com/ongil/backend/domain/brand/service/BrandService.java (1)

56-66: 빈 데이터가 장기간 지속될 때 DB 재조회 부하는 운영적으로 보완 권장합니다.

현재 구조에서는 실제 데이터가 비어 있는 동안 요청마다 DB를 조회합니다. 빈 결과 전용 키(또는 sentinel)를 짧은 TTL로만 저장하는 네거티브 캐시를 두면, 영구 빈 배열 캐싱은 피하면서도 DB 부하를 완화할 수 있습니다.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/ongil/backend/domain/brand/service/BrandService.java`
around lines 56 - 66, The code currently skips caching when response.isEmpty(),
causing repeated DB queries; update BrandService to write a negative cache entry
when response is empty by calling redisCacheService.save with a distinct key or
sentinel (e.g., CacheKeyConstants.BRANDS_ALL or a new
CacheKeyConstants.BRANDS_ALL_EMPTY) and a short TTL (add a new
CacheKeyConstants.BRANDS_ALL_EMPTY_TTL_HOURS or similar) instead of returning
immediately; retain the existing positive caching via
redisCacheService.save(CacheKeyConstants.BRANDS_ALL, response,
CacheKeyConstants.MASTER_DATA_TTL_HOURS) for non-empty responses and ensure the
lookup logic knows to treat the empty/sentinel key as an empty-result cache.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main/java/com/ongil/backend/domain/brand/service/BrandService.java`:
- Around line 56-66: The code currently skips caching when response.isEmpty(),
causing repeated DB queries; update BrandService to write a negative cache entry
when response is empty by calling redisCacheService.save with a distinct key or
sentinel (e.g., CacheKeyConstants.BRANDS_ALL or a new
CacheKeyConstants.BRANDS_ALL_EMPTY) and a short TTL (add a new
CacheKeyConstants.BRANDS_ALL_EMPTY_TTL_HOURS or similar) instead of returning
immediately; retain the existing positive caching via
redisCacheService.save(CacheKeyConstants.BRANDS_ALL, response,
CacheKeyConstants.MASTER_DATA_TTL_HOURS) for non-empty responses and ensure the
lookup logic knows to treat the empty/sentinel key as an empty-result cache.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc35cd4 and 2b1052f.

📒 Files selected for processing (2)
  • src/main/java/com/ongil/backend/domain/brand/service/BrandService.java
  • src/main/java/com/ongil/backend/domain/category/service/CategoryService.java

@kangcheolung kangcheolung added the 🐞 Fix 버그 수정 label Mar 3, 2026
@kangcheolung kangcheolung merged commit 1411544 into develop Mar 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 Fix 버그 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant