Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 캐싱 value 일부 수정 (#92) #93

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class FoodService {
private final UserRepository userRepository;

// 촬영 후, 음식 정보 저장
@CacheEvict(value = {"ResponseNutritionSumByDateDto"}, key = "#userId+createFoodDto.getDate()", cacheManager = "diareatCacheManager")
@Transactional
public Long saveFood(CreateFoodDto createFoodDto) {
if (foodRepository.existsByName(createFoodDto.getName())){
Expand All @@ -47,7 +48,7 @@ public Long saveFood(CreateFoodDto createFoodDto) {
return foodRepository.save(food).getId();
}

// 회원이 특정 날짜에 먹은 음식 조회
// 회원이 특정 날짜에 먹은 음식 조회 -> 돌발적인 행동이 많아 캐시 일관성 유지의 가치가 낮아서 캐싱 배제
@Transactional(readOnly = true)
public List<ResponseFoodDto> getFoodListByDate(Long userId, LocalDate date){
validateUser(userId);
Expand All @@ -58,7 +59,7 @@ public List<ResponseFoodDto> getFoodListByDate(Long userId, LocalDate date){
}

// 음식 정보 수정
@CacheEvict(value = "ResponseFoodDto, ResponseNutritionSumByDateDto", key = "#updateFoodDto.getUserId()+date.toString()", cacheManager = "diareatCacheManager")
@CacheEvict(value = {"ResponseNutritionSumByDateDto"}, key = "#updateFoodDto.getUserId()+date.toString()", cacheManager = "diareatCacheManager")
@Transactional
public void updateFood(UpdateFoodDto updateFoodDto, LocalDate date) {
Food food = getFoodById(updateFoodDto.getFoodId());
Expand All @@ -67,7 +68,7 @@ public void updateFood(UpdateFoodDto updateFoodDto, LocalDate date) {
}

// 음식 삭제
@CacheEvict(value = "ResponseFoodDto, ResponseNutritionSumByDateDto", key = "#userId+date.toString()", cacheManager = "diareatCacheManager")
@CacheEvict(value = {"ResponseNutritionSumByDateDto"}, key = "#userId+date.toString()", cacheManager = "diareatCacheManager")
@Transactional
public void deleteFood(Long foodId, Long userId, LocalDate date) {
validateFood(foodId, userId);
Expand Down