Skip to content

Commit

Permalink
Merge pull request #93 from CAUSOLDOUTMEN/feature/92-fix-redis
Browse files Browse the repository at this point in the history
Fix: 캐싱 value 일부 수정 (#92)
  • Loading branch information
synoti21 authored Nov 13, 2023
2 parents 0bbbf0a + a1f2a12 commit d0534e6
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit d0534e6

Please sign in to comment.