From 467dd26fc5ced460979d5ec6acbdbe22b34845d7 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Tue, 5 Nov 2024 22:27:58 +0900 Subject: [PATCH] =?UTF-8?q?#572=20[feat]=20=EA=B8=80=EB=AA=A8=EC=9E=84=20?= =?UTF-8?q?=EC=BA=90=EC=8B=9C=20=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EB=AA=A8=EB=93=88=20=EC=84=A4=EA=B3=84=20=EB=B0=8F?= =?UTF-8?q?=20=EB=B6=84=EC=82=B0=EB=9D=BD=20=EC=9C=84=EC=B9=98=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/mile/common/CacheService.java | 3 +++ ...MoimPopulerInfo.java => AtomicMoimPopulerInfo.java} | 2 +- .../mile/moim/service/lock/MoimPopularInfoAspect.java | 2 +- .../moim/service/popular/MoimPopularInfoRegister.java | 4 +--- .../moim/service/popular/MoimPopularInfoService.java | 10 ++++++++++ 5 files changed, 16 insertions(+), 5 deletions(-) rename module-domain/src/main/java/com/mile/moim/service/lock/{AtomicValidateMoimPopulerInfo.java => AtomicMoimPopulerInfo.java} (84%) 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(); + } + }