diff --git a/src/main/kotlin/com/yourssu/soongpt/common/config/CacheConfig.kt b/src/main/kotlin/com/yourssu/soongpt/common/config/CacheConfig.kt new file mode 100644 index 0000000..01df6a9 --- /dev/null +++ b/src/main/kotlin/com/yourssu/soongpt/common/config/CacheConfig.kt @@ -0,0 +1,23 @@ +package com.yourssu.soongpt.common.config + +import org.springframework.cache.CacheManager +import org.springframework.cache.annotation.EnableCaching +import org.springframework.cache.concurrent.ConcurrentMapCache +import org.springframework.cache.support.SimpleCacheManager +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +@EnableCaching +class CacheConfig { + @Bean + fun cacheManager(): CacheManager { + val cacheManager = SimpleCacheManager() + cacheManager.setCaches( + listOf( + ConcurrentMapCache("courseCache"), + ) + ) + return cacheManager + } +} diff --git a/src/main/kotlin/com/yourssu/soongpt/domain/course/business/CourseService.kt b/src/main/kotlin/com/yourssu/soongpt/domain/course/business/CourseService.kt index f02cd3a..6fddc5e 100644 --- a/src/main/kotlin/com/yourssu/soongpt/domain/course/business/CourseService.kt +++ b/src/main/kotlin/com/yourssu/soongpt/domain/course/business/CourseService.kt @@ -13,6 +13,7 @@ import com.yourssu.soongpt.domain.departmentGrade.implement.DepartmentGradeReade import com.yourssu.soongpt.domain.target.implement.Target import com.yourssu.soongpt.domain.target.implement.TargetReader import com.yourssu.soongpt.domain.target.implement.TargetWriter +import org.springframework.cache.annotation.Cacheable import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -29,6 +30,7 @@ class CourseService( private val targetWriter: TargetWriter, private val targetMapper: TargetMapper ) { + @Cacheable(value = ["courseCache"], key = "'majorRequired'.concat(#command.departmentName).concat(#command.grade)") fun findByDepartmentNameInMajorRequired(command: FoundDepartmentCommand): List { val department = departmentReader.getByName(command.departmentName) val departmentGrade = departmentGradeReader.getByDepartmentIdAndGrade(department.id!!, command.grade) @@ -43,6 +45,7 @@ class CourseService( }) } + @Cacheable(value = ["courseCache"], key = "'MajorElective'.concat(#command.departmentName).concat(#command.grade)") fun findByDepartmentNameInMajorElective(command: FoundDepartmentCommand): List { val department = departmentReader.getByName(command.departmentName) val courses = courseReader.findAllByDepartmentIdInMajorElective(department.id!!) @@ -55,6 +58,7 @@ class CourseService( }) } + @Cacheable(value = ["courseCache"], key = "'GeneralRequired'.concat(#command.departmentName).concat(#command.grade)") fun findByDepartmentNameInGeneralRequired(command: FoundDepartmentCommand): List { val department = departmentReader.getByName(command.departmentName) val departmentGrade = departmentGradeReader.getByDepartmentIdAndGrade(department.id!!, command.grade) @@ -152,4 +156,4 @@ class CourseService( val target = targetReader.findAllByCourseId(courseId) return CourseResponse.from(course, target, courseTimes) } -} \ No newline at end of file +}