Skip to content

Commit

Permalink
Merge pull request #379 from Team-Ampersand/delete-music-list-cache
Browse files Browse the repository at this point in the history
Delete music list cache
  • Loading branch information
esperar committed Jul 7, 2024
2 parents b3435c8 + 82629b9 commit 2ffdb41
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.dotori.v2.domain.member.enums.MusicStatus
import com.dotori.v2.domain.music.domain.entity.Music
import com.dotori.v2.domain.music.domain.repository.MusicRepository
import com.dotori.v2.domain.music.exception.MusicNotFoundException
import com.dotori.v2.domain.music.presentation.data.res.MusicListResDto
import com.dotori.v2.domain.music.service.DeleteMusicService
import com.dotori.v2.global.config.redis.service.RedisCacheService
import org.springframework.data.repository.findByIdOrNull
Expand All @@ -16,15 +17,13 @@ class DeleteMusicServiceImpl(
private val musicRepository: MusicRepository,
private val redisCacheService: RedisCacheService
) : DeleteMusicService {

override fun execute(musicId: Long) {
val music: Music = musicRepository.findByIdOrNull(musicId) ?: throw MusicNotFoundException()

val key = "musicList:${music.createdDate.toLocalDate()}"

if(redisCacheService.getFromCache(key) != null) {
redisCacheService.deleteFromCache(key)
}
val date = music.createdDate.toLocalDate().toString()

redisCacheService.putToCacheMusic(date, MusicListResDto(mutableListOf()))
musicRepository.delete(music)
music.member.updateMusicStatus(MusicStatus.CAN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.dotori.v2.domain.music.domain.entity.Music
import com.dotori.v2.domain.music.domain.repository.MusicRepository
import com.dotori.v2.domain.music.exception.MusicNotFoundException
import com.dotori.v2.domain.music.exception.NotMyMusicException
import com.dotori.v2.domain.music.presentation.data.res.MusicListResDto
import com.dotori.v2.domain.music.service.DeleteMyMusicService
import com.dotori.v2.global.config.redis.service.RedisCacheService
import com.dotori.v2.global.util.UserUtil
Expand All @@ -28,12 +29,9 @@ class DeleteMyMusicServiceImpl(

validMusic(music, member)

val key = "musicList:${music.createdDate.toLocalDate()}"

if(redisCacheService.getFromCache(key) != null) {
redisCacheService.deleteFromCache(key)
}
val date = music.createdDate.toLocalDate().toString()

redisCacheService.putToCacheMusic(date, MusicListResDto(mutableListOf()))
musicRepository.delete(music)
music.member.updateMusicStatus(MusicStatus.CAN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class FindMusicsServiceImpl(
val cachedData = redisCacheService.getFromCacheMusic(date.toString())

if(cachedData != null) {
return cachedData as MusicListResDto
val response = cachedData as MusicListResDto
if(response.content.isNotEmpty()) {
return response
}
}

val response = MusicListResDto(
Expand Down

0 comments on commit 2ffdb41

Please sign in to comment.