Hchanghyeon / dev-troubleshooting

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

[프록시] Self Invocation 트러블 슈팅 #2

Closed Hchanghyeon closed 9 months ago

Hchanghyeon commented 9 months ago

문제 상황

@Transactional(readOnly = true)
public GamesAndLocationResponse findGamesWithInAddress(
            final String addressDepth1,
            final String addressDepth2
 ) {
        final MainAddressResponse mainAddressResponse = addressService.findMainAddressByNames(addressDepth1,
                addressDepth2);

        final List<Game> games = gameRepository.findGamesWithInAddress(
                mainAddressResponse.getAddressDepth1(),
                mainAddressResponse.getAddressDepth2()
        );

        final MapPolygon polygon = getMapPolygon(mainAddressResponse); // AOP 내부에서 @Cacheable 호출

        final List<GameResponse> gameResponses = games.stream()
                .map(game -> GameResponse.of(game, getMemberResponses(game, CONFIRMED)))
                .toList();

        return GamesAndLocationResponse.of(gameResponses, polygon);
}

@Cacheable("polygon") // Self Invocation 문제로 동작 안함
public MapPolygon getMapPolygon(final MainAddressResponse mainAddressResponse) {
     return mapPolygonRepository.findByAddressDepth1AndAddressDepth2(
                mainAddressResponse.getAddressDepth1(),
                mainAddressResponse.getAddressDepth2()
     );
}

위와 같이 getMapPolygon을 호출했을 때 @Cacheable이 동작하지 못하는 현상 발생

Hchanghyeon commented 9 months ago

해결: Self Invocation 트러블 슈팅