Skip to content

Commit 86a0037

Browse files
committed
feat: 상품 상세 조회 무효화 전략
- 상품의 가격이 변경될 때 캐싱된 데이터를 Redis에서 제거합니다.
1 parent 7b757e2 commit 86a0037

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/application/product/ProductFacade.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import com.loopers.support.error.CoreException;
99
import com.loopers.support.error.ErrorType;
1010
import lombok.RequiredArgsConstructor;
11+
import org.springframework.cache.annotation.CacheEvict;
1112
import org.springframework.cache.annotation.Cacheable;
1213
import org.springframework.stereotype.Component;
1314
import org.springframework.transaction.annotation.Transactional;
1415

16+
import java.math.BigDecimal;
1517
import java.util.List;
1618

1719
@Component
@@ -67,4 +69,19 @@ public List<ProductInfo> searchProductsByCondition(ProductV1Dto.SearchProductReq
6769
.map(ProductInfo::from)
6870
.toList();
6971
}
72+
73+
@Transactional
74+
@CacheEvict(value = "product", key = "#request.id()")
75+
public ProductInfo changePrice(ProductV1Dto.ChangePriceRequest request) {
76+
Long id = request.id();
77+
BigDecimal newPrice = request.newPrice();
78+
79+
Product product = productRepository.findById(id).orElseThrow(
80+
() -> new CoreException(ErrorType.NOT_FOUND, "존재하지 않는 상품입니다.")
81+
);
82+
83+
Product changedProduct = product.changePrice(newPrice);
84+
85+
return ProductInfo.from(changedProduct);
86+
}
7087
}

0 commit comments

Comments
 (0)