diff --git a/module-domain/src/main/java/com/mile/common/CacheService.java b/module-domain/src/main/java/com/mile/common/CacheService.java index 5f6463e6..7bce197e 100644 --- a/module-domain/src/main/java/com/mile/common/CacheService.java +++ b/module-domain/src/main/java/com/mile/common/CacheService.java @@ -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; @@ -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(); } diff --git a/module-domain/src/main/java/com/mile/moim/service/lock/AtomicValidateMoimPopulerInfo.java b/module-domain/src/main/java/com/mile/moim/service/lock/AtomicMoimPopulerInfo.java similarity index 84% rename from module-domain/src/main/java/com/mile/moim/service/lock/AtomicValidateMoimPopulerInfo.java rename to module-domain/src/main/java/com/mile/moim/service/lock/AtomicMoimPopulerInfo.java index 6be34794..1b158e4f 100644 --- a/module-domain/src/main/java/com/mile/moim/service/lock/AtomicValidateMoimPopulerInfo.java +++ b/module-domain/src/main/java/com/mile/moim/service/lock/AtomicMoimPopulerInfo.java @@ -8,5 +8,5 @@ @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) -public @interface AtomicValidateMoimPopulerInfo { +public @interface AtomicMoimPopulerInfo { } diff --git a/module-domain/src/main/java/com/mile/moim/service/lock/MoimPopularInfoAspect.java b/module-domain/src/main/java/com/mile/moim/service/lock/MoimPopularInfoAspect.java index 920ce941..5cb88fa7 100644 --- a/module-domain/src/main/java/com/mile/moim/service/lock/MoimPopularInfoAspect.java +++ b/module-domain/src/main/java/com/mile/moim/service/lock/MoimPopularInfoAspect.java @@ -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() { } diff --git a/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoRegister.java b/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoRegister.java index 6a6d6a89..c2a18ac0 100644 --- a/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoRegister.java +++ b/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoRegister.java @@ -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; @@ -46,7 +45,6 @@ private Set getMoimCuriousWriter(final List mostCuriousPostsInLastWeek = curiousRetriever.findMostCuriousPostsInLastWeek(moim); diff --git a/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoService.java b/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoService.java index 53ccf0df..90943c76 100644 --- a/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoService.java +++ b/module-domain/src/main/java/com/mile/moim/service/popular/MoimPopularInfoService.java @@ -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; @@ -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) @@ -31,4 +35,10 @@ public void deleteAllForScheduled() { moimPopularInfoRepository.deleteAllInBatch(); } + @Scheduled(cron = "59 59 23 * * *") + public void deleteCacheForScheduled() { + sendMessageModule.sendMessage("글모임 별 인기 글/인기 작가 캐시 삭제 완료"); + cacheService.deleteMoimCache(); + } + }