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

[BE] feat: Spring Cache 적용 #792

Merged
merged 26 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
09e0698
build: Spring Cache 의존성 추가
donghoony Oct 8, 2024
d0ca018
feat: `Application`에 `@EnableCaching` 적용
donghoony Oct 8, 2024
37fdfb7
feat: `ConcurrentHashMapCacheManager` 적용
donghoony Oct 8, 2024
8d616fd
feat: 템플릿 응답 객체 캐싱 적용
donghoony Oct 8, 2024
4cb71d5
refactor: `local`, `dev`, `prod`에서만 캐싱을 활용하도록 변경
donghoony Oct 8, 2024
da1c00e
chore: caffeine cache 의존성 추가
donghoony Oct 8, 2024
dc3807c
chore: 캐시 상세 설정
skylar1220 Nov 5, 2024
dd77084
chore: 캐시 이름 변경 및 지정
skylar1220 Nov 5, 2024
f783dc8
refactor: 리뷰 목록 조회 로직에 캐시 적용
skylar1220 Nov 5, 2024
171c33a
refactor: 리뷰 모아보기 로직에 캐시 적용
skylar1220 Nov 5, 2024
405d219
refactor: 호출 테이블에 맞게 메서드 이동
skylar1220 Nov 5, 2024
28a59c5
refactor: 리뷰 상세 조회 로직에 캐시 적용
skylar1220 Nov 5, 2024
a86965b
refactor: 사용하지 않는 메서드 제거
skylar1220 Nov 5, 2024
a7865d7
refactor: 리뷰 작성 로직에 캐시 적용
skylar1220 Nov 5, 2024
e7f8bb5
refactor: 동일한 반환 타입, 키값인 경우 충돌을 방지하기 위해 캐시키에 클래스, 메서드 정보 추가
skylar1220 Nov 5, 2024
bf246cb
refactor: 키 식별자에 클래스, 메서드명을 동적으로 주입하도록 변경
skylar1220 Nov 5, 2024
6f3a2be
refactor: 키 식별자를 생성하는 객체 분리
skylar1220 Nov 5, 2024
3ce1703
refactor: customKeyGenerator을 클래스 단위에서 적용하도록 모든 캐시에 적용
skylar1220 Nov 5, 2024
888a3be
refactor: 템플릿 조회를 제외한 나머지 부분 캐시 제거
skylar1220 Nov 17, 2024
3dde794
refactor: caffeine 설정 제거 및 명시적으로 캐시 이름을 config에서 지정하지 않는 방식으로 변경
skylar1220 Nov 17, 2024
90e154a
chore: 카페인 캐시 라이브러리 의존성 제거
skylar1220 Nov 17, 2024
4c14473
refactor: 동일한 반환 타입, 키값인 경우 충돌을 방지하기 위해 캐시키에 클래스, 메서드 정보 추가
skylar1220 Nov 17, 2024
2dee7f4
refactor: 캐시 value명 변경
skylar1220 Nov 18, 2024
f50578a
refactor: 캐시 profile 적용을 메서드 단위로 적용
skylar1220 Nov 18, 2024
ad9360b
refactor: value로 캐시를 구분하고 key는 기본 형태로 저장하게 변경
skylar1220 Nov 18, 2024
23fc0cd
chore: 테스트 환경에서 Redis cache가 자동으로 활성화 되지 않도록 캐시 비활성화 재정의
skylar1220 Nov 18, 2024
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
1 change: 1 addition & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
Expand Down
19 changes: 19 additions & 0 deletions backend/src/main/java/reviewme/config/CacheManagerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package reviewme.config;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@EnableCaching
public class CacheManagerConfig {

@Profile({"local", "dev", "prod"})
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import reviewme.question.domain.OptionGroup;
import reviewme.question.domain.OptionItem;
Expand All @@ -14,17 +15,17 @@
import reviewme.template.domain.SectionQuestion;
import reviewme.template.domain.Template;
import reviewme.template.domain.TemplateSection;
import reviewme.template.service.exception.MissingOptionItemsInOptionGroupException;
import reviewme.template.service.exception.SectionInTemplateNotFoundException;
import reviewme.template.service.exception.TemplateNotFoundByReviewGroupException;
import reviewme.template.repository.SectionRepository;
import reviewme.template.repository.TemplateRepository;
import reviewme.template.service.dto.response.OptionGroupResponse;
import reviewme.template.service.dto.response.OptionItemResponse;
import reviewme.template.service.dto.response.QuestionResponse;
import reviewme.template.service.dto.response.SectionResponse;
import reviewme.template.service.dto.response.TemplateResponse;
import reviewme.template.service.exception.MissingOptionItemsInOptionGroupException;
import reviewme.template.service.exception.QuestionInSectionNotFoundException;
import reviewme.template.service.exception.SectionInTemplateNotFoundException;
import reviewme.template.service.exception.TemplateNotFoundByReviewGroupException;

@Component
@RequiredArgsConstructor
Expand All @@ -38,6 +39,7 @@ public class TemplateMapper {
private final OptionGroupRepository optionGroupRepository;
private final OptionItemRepository optionItemRepository;

@Cacheable(value = "template_response", key = "#reviewGroup.templateId")
public TemplateResponse mapToTemplateResponse(ReviewGroup reviewGroup) {
Template template = templateRepository.findById(reviewGroup.getTemplateId())
.orElseThrow(() -> new TemplateNotFoundByReviewGroupException(
Expand Down
2 changes: 2 additions & 0 deletions backend/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ spring:
ddl-auto: update
flyway:
enabled: false
cache:
type: none

springdoc:
swagger-ui:
Expand Down