Hchanghyeon / dev-troubleshooting

개발하며 마주쳤던 크고 작은 문제들과 고민들
1 stars 0 forks source link

[캐시] 로컬 캐시를 저장하지 못하는 현상 트러블 슈팅 #3

Closed Hchanghyeon closed 9 months ago

Hchanghyeon commented 9 months ago

문제 상황

@Service
@RequiredArgsConstructor
public class MapService {

    private final MapPolygonRepository mapPolygonRepository;

    @Transactional(readOnly = true)
    @Cacheable(cacheManager = "caffeineCacheManager", cacheNames = "polygon")
    public MapPolygon findMapPolygonByMainAddress(final MainAddressResponse mainAddressResponse) {
        return mapPolygonRepository.findByAddressDepth1AndAddressDepth2(
                mainAddressResponse.getAddressDepth1(),
                mainAddressResponse.getAddressDepth2()
        );
    }
}

위와 같이 코드를 작성했을 때 동일한 mainAddressResponse 값으로 보내도 캐시에서 조회되지않고 DB에 쿼리가 나가는 현상 발생

Hchanghyeon commented 9 months ago

해결: 로컬 캐시를 저장하지 못하는 현상 트러블 슈팅