Skip to content

Commit

Permalink
feat: 과목 조회 API 캐싱
Browse files Browse the repository at this point in the history
  • Loading branch information
DWL21 committed Feb 16, 2025
1 parent 04ffe99 commit cedf8da
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/main/kotlin/com/yourssu/soongpt/common/config/CacheConfig.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<CourseResponse> {
val department = departmentReader.getByName(command.departmentName)
val departmentGrade = departmentGradeReader.getByDepartmentIdAndGrade(department.id!!, command.grade)
Expand All @@ -43,6 +45,7 @@ class CourseService(
})
}

@Cacheable(value = ["courseCache"], key = "'MajorElective'.concat(#command.departmentName).concat(#command.grade)")
fun findByDepartmentNameInMajorElective(command: FoundDepartmentCommand): List<CourseResponse> {
val department = departmentReader.getByName(command.departmentName)
val courses = courseReader.findAllByDepartmentIdInMajorElective(department.id!!)
Expand All @@ -55,6 +58,7 @@ class CourseService(
})
}

@Cacheable(value = ["courseCache"], key = "'GeneralRequired'.concat(#command.departmentName).concat(#command.grade)")
fun findByDepartmentNameInGeneralRequired(command: FoundDepartmentCommand): List<CourseResponse> {
val department = departmentReader.getByName(command.departmentName)
val departmentGrade = departmentGradeReader.getByDepartmentIdAndGrade(department.id!!, command.grade)
Expand Down Expand Up @@ -152,4 +156,4 @@ class CourseService(
val target = targetReader.findAllByCourseId(courseId)
return CourseResponse.from(course, target, courseTimes)
}
}
}

0 comments on commit cedf8da

Please sign in to comment.