Skip to content

Commit

Permalink
[BE] feat: Spring Cache 적용 (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
donghoony authored Nov 20, 2024
1 parent 418382c commit fa7d3d3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
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.template.domain.OptionGroup;
import reviewme.template.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

0 comments on commit fa7d3d3

Please sign in to comment.