Skip to content

Commit c157454

Browse files
authored
Merge pull request #152 from team-gogo/feature/community-community-about-cache
[community] 커뮤니티 관련 API 캐싱
2 parents d5d31b3 + 60e1d22 commit c157454

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/main/kotlin/gogo/gogostage/domain/community/root/application/CommunityProcessor.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import gogo.gogostage.domain.community.comment.persistence.CommentRepository
99
import gogo.gogostage.domain.community.commentlike.persistence.CommentLike
1010
import gogo.gogostage.domain.community.commentlike.persistence.CommentLikeRepository
1111
import gogo.gogostage.domain.community.root.application.dto.*
12+
import gogo.gogostage.global.cache.CacheConstant
13+
import gogo.gogostage.global.cache.RedisCacheService
1214
import gogo.gogostage.global.error.StageException
1315
import gogo.gogostage.global.internal.student.stub.StudentByIdStub
1416
import org.springframework.http.HttpStatus
@@ -21,7 +23,7 @@ class CommunityProcessor(
2123
private val commentRepository: CommentRepository,
2224
private val commentLikeRepository: CommentLikeRepository,
2325
private val commentMapper: CommunityMapper,
24-
private val boardRepository: BoardRepository
26+
private val boardRepository: BoardRepository,
2527
) {
2628

2729
fun likeBoard(studentId: Long, board: Board): LikeResDto {

src/main/kotlin/gogo/gogostage/domain/community/root/application/CommunityServiceImpl.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import gogo.gogostage.domain.community.root.application.dto.*
66
import gogo.gogostage.domain.community.root.persistence.SortType
77
import gogo.gogostage.domain.game.persistence.GameCategory
88
import gogo.gogostage.domain.stage.root.application.StageValidator
9+
import gogo.gogostage.global.cache.CacheConstant
910
import gogo.gogostage.global.util.UserContextUtil
11+
import org.springframework.cache.annotation.CacheEvict
12+
import org.springframework.cache.annotation.Cacheable
1013
import org.springframework.stereotype.Service
1114
import org.springframework.transaction.annotation.Transactional
1215

@@ -41,6 +44,7 @@ class CommunityServiceImpl(
4144
}
4245

4346
@Transactional(readOnly = true)
47+
@Cacheable(value = [CacheConstant.COMMUNITY_INFO_CACHE_VALUE], key = "#boardId", cacheManager = "cacheManager")
4448
override fun getStageBoardInfo(boardId: Long): GetCommunityBoardInfoResDto {
4549
val student = userUtil.getCurrentStudent()
4650
val board = boardReader.read(boardId)
@@ -51,6 +55,7 @@ class CommunityServiceImpl(
5155
}
5256

5357
@Transactional
58+
@CacheEvict(value = [CacheConstant.COMMUNITY_INFO_CACHE_VALUE], key = "#boardId", cacheManager = "cacheManager")
5459
override fun likeStageBoard(boardId: Long): LikeResDto {
5560
val student = userUtil.getCurrentStudent()
5661
val board = communityReader.readBoardByBoardIdForWrite(boardId)
@@ -59,6 +64,7 @@ class CommunityServiceImpl(
5964
}
6065

6166
@Transactional
67+
@CacheEvict(value = [CacheConstant.COMMUNITY_INFO_CACHE_VALUE], key = "#boardId", cacheManager = "cacheManager")
6268
override fun writeBoardComment(boardId: Long, writeBoardCommentDto: WriteBoardCommentReqDto): WriteBoardCommentResDto {
6369
val student = userUtil.getCurrentStudent()
6470
val board = communityReader.readBoardByBoardId(boardId)
@@ -68,6 +74,7 @@ class CommunityServiceImpl(
6874
}
6975

7076
@Transactional
77+
@CacheEvict(value = [CacheConstant.COMMUNITY_INFO_CACHE_VALUE], key = "#boardId", cacheManager = "cacheManager")
7178
override fun likeBoardComment(commentId: Long): LikeResDto {
7279
val student = userUtil.getCurrentStudent()
7380
val comment = communityReader.readCommentByCommentIdForWrite(commentId)

src/main/kotlin/gogo/gogostage/global/cache/CacheConstant.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ object CacheConstant {
88
const val GAME_CACHE_VALE = "game"
99
const val GAME_FORMAT_CACHE_VALUE = "game_format"
1010
const val MATCH_INFO_CACHE_VALUE = "match_info"
11+
const val COMMUNITY_INFO_CACHE_VALUE = "community_info"
1112
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package gogo.gogostage.global.internal.user.stub
22

3+
import com.fasterxml.jackson.annotation.JsonProperty
4+
35
enum class Sex {
4-
MALE, FEMALE
6+
@JsonProperty("MALE")
7+
MALE,
8+
@JsonProperty("FEMALE")
9+
FEMALE
510
}

0 commit comments

Comments
 (0)