본문으로 건너뛰기

Spring Cache — @Cacheable, @CachePut, @CacheEvict

개요: 메서드 단위 캐시 선언과 Redis 백엔드 연결을 정리합니다. slug /knowledge/k-caching-annotation을 유지합니다.

애너테이션​

애너테이션역할
@EnableCaching캐싱 기능 활성화
@Cacheable없으면 실행 후 저장, 있으면 반환
@CachePut항상 실행 후 캐시 갱신
@CacheEvict삭제 (allEntries로 prefix 일괄)
@Caching여러 동작 조합

boot-base 흐름​

@Cacheable / @CacheEvict
→ CachePortCacheManager / CachePortCache
→ CachePort (RedisCacheAdapter)
→ StringRedisTemplate (Lettuce)

값은 JsonCacheValueCodec(JSON)입니다.
앱에 RedisCacheManager를 두지 않습니다.
Gateway JWT는 @Cacheable이 아니라 CachePort 직접입니다.

상세: lib-cache
패턴: 캐시 Cache-Aside
Ref: boot-base