Skip to content

Commit

Permalink
fix: 캐시 초기화 문제 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yujamint committed Jul 25, 2024
1 parent 3118ff7 commit 9ee74a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,17 @@ public Page<CategorizedProblem> findCategorizedProblemsByCategoryId(Long categor
return categorizedProblemRepository.findByCategoryCategoryId(categoryId, pageRequest);
}


public void deleteCategorizedProblem(Long categorizedProblemID){
@CacheEvict(value = "categorizedProblem", key = "#result")
public Long deleteCategorizedProblem(Long categorizedProblemID) {
CategorizedProblem categorizedProblem = findVerifiedCategorizedProblemByCategorizedProblemId(categorizedProblemID);
Long categoryId = categorizedProblem.getCategory().getCategoryId();
deleteAndEvictCache(categorizedProblem, categoryId);
}

@CacheEvict(value = "categorizedProblem", key = "#categoryId")
public void deleteAndEvictCache(CategorizedProblem categorizedProblem, Long categoryId) {
categorizedProblemRepository.deleteById(categorizedProblem.getCategorizedProblemId());

Problem problem = categorizedProblem.getProblem();
Long problemId = problem.getProblemId();
if (problem.isMemberSavedProblem() && !isProblemUsedInOtherCategorizedProblems(problemId)) {
problemService.deleteProblem(problemId);
}
return categorizedProblem.getCategory().getCategoryId();
}

private boolean isProblemUsedInOtherCategorizedProblems(Long problemId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public SummaryDto.pdfResponse createSummaryPdf(Long categorizedSummaryId) throws
return summaryService.createSummaryPdf(summaryId);
}

@CacheEvict(value = "categorizedSummary", key = "#categoryId")
@CacheEvict(value = "categorizedSummary", key = "#result.getCategory().getCategoryId()")
public CategorizedSummary updateCategorizedSummary(Long categorizedSummaryId, SummaryDto.Patch summaryPatchDto) {
CategorizedSummary categorizedSummary = findVerifiedCategorizedSummaryByCategorizedSummaryId(categorizedSummaryId);
summaryService.updateSummary(
Expand All @@ -87,8 +87,8 @@ public CategorizedSummary updateCategorizedSummary(Long categorizedSummaryId, Su
return categorizedSummaryRepository.save(categorizedSummary);
}

@CacheEvict(value = "categorizedSummary", key = "#categoryId")
public void deleteCategorizedSummary(Long categorizedSummaryId) {
@CacheEvict(value = "categorizedSummary", key = "#result")
public Long deleteCategorizedSummary(Long categorizedSummaryId) {
CategorizedSummary categorizedSummary = findVerifiedCategorizedSummaryByCategorizedSummaryId(categorizedSummaryId);

categorizedSummaryRepository.deleteById(categorizedSummaryId);
Expand All @@ -98,6 +98,8 @@ public void deleteCategorizedSummary(Long categorizedSummaryId) {
if (summary.isMemberSavedSummary() && !isSummaryUsedInOtherCategorizedSummarys(summaryId)) {
summaryRepository.deleteById(summaryId);
}
Long categoryId = categorizedSummary.getCategory().getCategoryId();
return categoryId;
}

private boolean isSummaryUsedInOtherCategorizedSummarys(Long summaryId){
Expand Down

0 comments on commit 9ee74a0

Please sign in to comment.