Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release snapshot #574

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}

}
Loading