Skip to content

Commit

Permalink
#572 [feat] 글모임 캐시 삭제 시 알림 모듈 설계 및 분산락 위치 변경
Browse files Browse the repository at this point in the history
#572 [feat] 글모임 캐시 삭제 시 알림 모듈 설계 및 분산락 위치 변경
  • Loading branch information
sohyundoh authored Nov 5, 2024
2 parents 921717e + 467dd26 commit 48785d3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions module-domain/src/main/java/com/mile/common/CacheService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mile.common;

import com.mile.slack.module.SendMessageModule;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;
Expand All @@ -10,8 +11,10 @@ public class CacheService {

private final String MOIM_CACHE_NAME = "moimPopularInfo";
private final CacheManager cacheManager;
private final SendMessageModule sendMessageModule;

public void deleteMoimCache() {
sendMessageModule.sendMessage("INTERNAL API 호출) 글모임 별 인기 글/ 작가에 대한 캐시 삭제 완료");
if (cacheManager.getCache(MOIM_CACHE_NAME) != null) {
cacheManager.getCache(MOIM_CACHE_NAME).clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface AtomicValidateMoimPopulerInfo {
public @interface AtomicMoimPopulerInfo {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MoimPopularInfoAspect {
private final static String MOIM_POPULAR_LOCK = "MOIM_POPULAR_LOCK : ";
private final AopForTransaction aopForTransaction;

@Pointcut("@annotation(com.mile.moim.service.lock.AtomicValidateMoimPopulerInfo)")
@Pointcut("@annotation(com.mile.moim.service.lock.AtomicMoimPopulerInfo)")
public void setMoimPoplarInfoCut() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import com.mile.moim.domain.popular.MoimCuriousWriter;
import com.mile.moim.domain.popular.MoimPopularInfo;
import com.mile.moim.repository.MoimPopularInfoRepository;
import com.mile.moim.service.lock.AtomicValidateMoimPopulerInfo;
import com.mile.moim.service.lock.AtomicMoimPopulerInfo;
import com.mile.writername.domain.WriterName;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CachePut;
import org.springframework.scheduling.concurrent.ScheduledExecutorTask;
import org.springframework.stereotype.Component;

import java.util.Comparator;
Expand Down Expand Up @@ -46,7 +45,6 @@ private Set<MoimCuriousWriter> getMoimCuriousWriter(final List<PostAndCuriousCou
}

@CachePut(value = "moimPopularInfo", key = "#moim.id")
@AtomicValidateMoimPopulerInfo
public MoimPopularInfo setMostPopularInfoOfMoim(final Moim moim) {
List<PostAndCuriousCountInLastWeek> mostCuriousPostsInLastWeek = curiousRetriever.findMostCuriousPostsInLastWeek(moim);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.mile.moim.service.popular;

import com.mile.common.CacheService;
import com.mile.moim.domain.Moim;
import com.mile.moim.domain.popular.MoimPopularInfo;
import com.mile.moim.repository.MoimPopularInfoRepository;
import com.mile.moim.service.lock.AtomicMoimPopulerInfo;
import com.mile.slack.module.SendMessageModule;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,9 +18,11 @@ public class MoimPopularInfoService {
private final MoimPopularInfoRepository moimPopularInfoRepository;
private final MoimPopularInfoRegister moimPopularInfoRegister;
private final SendMessageModule sendMessageModule;
private final CacheService cacheService;


@Cacheable(value = "moimPopularInfo", key = "#moim.id")
@AtomicMoimPopulerInfo
public MoimPopularInfo getMoimPopularInfo(final Moim moim) {
return moimPopularInfoRepository.findByMoimId(moim.getId()).orElseGet(
() -> moimPopularInfoRegister.setMostPopularInfoOfMoim(moim)
Expand All @@ -31,4 +35,10 @@ public void deleteAllForScheduled() {
moimPopularInfoRepository.deleteAllInBatch();
}

@Scheduled(cron = "59 59 23 * * *")
public void deleteCacheForScheduled() {
sendMessageModule.sendMessage("글모임 별 인기 글/인기 작가 캐시 삭제 완료");
cacheService.deleteMoimCache();
}

}

0 comments on commit 48785d3

Please sign in to comment.