You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
init Server -> application load -> `@PostConstruct` 로 데이터베이스에서 데이터 call
-> Local HashMap에 캐싱 데이터 저장 -> 요청 시 캐싱 데이터 사용 -> 주기마다 데이터베이스 polling 하여 최신 데이터 업데이트
Update Cache Logic
어드민이 캐시를 직접 invalidate하는 방법으로, 서버가 1대라면 api 요청으로 처리가능.
but 2대 이상이라면 api 요청이 어떤 서버로 갈지 알 수 없음. 따라서 pub-sub or mq를 사용하는 경우가 많음.
redis를 도입한다면 pub-sub사용 (High Consistency)
데이터 양이 많지 않기에 DB 폴링으로만 해결 (변경이 즉시 반영되지 않음.)
pseudo code
class EggMemoryCache {
private final Map<String, EggCacheData> cacheMap;
private final EggRepository eggRepository;
...
@Override
public List<Egg> getAll() {
return cacheMap.values().stream().map ....
}
@PostConstruct
public void buildCache() {
List<Egg> eggs = eggRepository.findAll();
...
for ..
cacheMap.put(x, e)
}
@Scheduled
public void updateCacheRepeatable() {}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
이슈
알, 러니모는 변경되는 데이터인가?
Enum으로 관리한다면 변경마다 배포를 다시해야함.
데이터베이스에서 조회하되 로컬 캐싱을 하는 것으로 변경
두 가지 이유로 캐싱을 하여 사용해도 문제가 없을 것이라 생각됩니다.
how?
어드민이 캐시를 직접 invalidate하는 방법으로, 서버가 1대라면 api 요청으로 처리가능.
but 2대 이상이라면 api 요청이 어떤 서버로 갈지 알 수 없음. 따라서 pub-sub or mq를 사용하는 경우가 많음.
pseudo code
Beta Was this translation helpful? Give feedback.
All reactions