-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from solid-connection/main
[RELEASE] 캐싱 도입 및 모니터링 환경 구축, 지원서 선택지 비필수 전환, 조회수 갱신 오류 수정, nginx max body size 조정
- Loading branch information
Showing
28 changed files
with
630 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
## 어떤 버그인가요 | ||
|
||
> 문제가 되는 부분에 대해 설명해주세요 | ||
## 재현 방법(선택) | ||
버그를 재현할 수 있는 과정을 설명해주세요(필요하다면 사진을 첨부해주세요) | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
## 참고할만한 자료(선택) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/example/solidconnection/cache/CacheUpdateListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.solidconnection.cache; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.redis.connection.Message; | ||
import org.springframework.data.redis.connection.MessageListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CacheUpdateListener implements MessageListener { | ||
|
||
private final CompletableFutureManager futureManager; | ||
@Override | ||
public void onMessage(Message message, byte[] pattern) { | ||
String messageBody = new String(message.getBody(), StandardCharsets.UTF_8).replaceAll("^\"|\"$", ""); | ||
futureManager.completeFuture(messageBody); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/example/solidconnection/cache/CachingAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.example.solidconnection.cache; | ||
|
||
import com.example.solidconnection.cache.annotation.DefaultCacheOut; | ||
import com.example.solidconnection.cache.annotation.DefaultCaching; | ||
import com.example.solidconnection.cache.manager.CacheManager; | ||
import com.example.solidconnection.util.RedisUtils; | ||
import lombok.RequiredArgsConstructor; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Aspect | ||
@Component | ||
@RequiredArgsConstructor | ||
public class CachingAspect { | ||
private final ApplicationContext applicationContext; | ||
private final RedisUtils redisUtils; | ||
|
||
@Around("@annotation(defaultCaching)") | ||
public Object cache(ProceedingJoinPoint joinPoint, DefaultCaching defaultCaching) throws Throwable { | ||
|
||
CacheManager cacheManager = (CacheManager) applicationContext.getBean(defaultCaching.cacheManager()); | ||
String key = redisUtils.generateCacheKey(defaultCaching.key(), joinPoint.getArgs()); | ||
Long ttl = defaultCaching.ttlSec(); | ||
|
||
// 1. 캐시에 있으면 반환 | ||
Object cachedValue = cacheManager.get(key); | ||
if (cachedValue != null) { | ||
return cachedValue; | ||
} | ||
// 2. 캐시에 없으면 캐싱 후 반환 | ||
Object result = joinPoint.proceed(); | ||
cacheManager.put(key, result, ttl); | ||
return result; | ||
} | ||
|
||
@Around("@annotation(defaultCacheOut)") | ||
public Object cacheEvict(ProceedingJoinPoint joinPoint, DefaultCacheOut defaultCacheOut) throws Throwable { | ||
|
||
CacheManager cacheManager = (CacheManager) applicationContext.getBean(defaultCacheOut.cacheManager()); | ||
|
||
for (String key : defaultCacheOut.key()) { | ||
String cacheKey = redisUtils.generateCacheKey(key, joinPoint.getArgs()); | ||
boolean usingPrefix = defaultCacheOut.prefix(); | ||
|
||
if (usingPrefix) { | ||
cacheManager.evictUsingPrefix(cacheKey); | ||
}else{ | ||
cacheManager.evict(cacheKey); | ||
} | ||
} | ||
return joinPoint.proceed(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/solidconnection/cache/CompletableFutureManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.solidconnection.cache; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class CompletableFutureManager { | ||
private final Map<String, CompletableFuture<Void>> waitingRequests = new ConcurrentHashMap<>(); | ||
|
||
public CompletableFuture<Void> getOrCreateFuture(String key) { | ||
return waitingRequests.computeIfAbsent(key, k -> new CompletableFuture<>()); | ||
} | ||
|
||
public void completeFuture(String key) { | ||
CompletableFuture<Void> future = waitingRequests.remove(key); | ||
if (future != null) { | ||
future.complete(null); | ||
} | ||
} | ||
} |
Oops, something went wrong.