Skip to content

Commit

Permalink
add :: deleteFromCacheMusic
Browse files Browse the repository at this point in the history
  • Loading branch information
ta2ye0n committed Sep 23, 2024
1 parent f0a502c commit 9ba1cd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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.MusicLikeCountResDto
import com.dotori.v2.domain.music.service.ToggleMusicLikeService
import com.dotori.v2.global.config.redis.service.RedisCacheService
import com.dotori.v2.global.util.UserUtil
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
Expand All @@ -18,7 +19,8 @@ import org.springframework.transaction.annotation.Transactional
class ToggleMusicLikeServiceImpl(
private val musicLikeRepository: MusicLikeRepository,
private val musicRepository: MusicRepository,
private val userUtil: UserUtil
private val userUtil: UserUtil,
private val redisCacheService: RedisCacheService
): ToggleMusicLikeService {
override fun execute(musicId: Long) : MusicLikeCountResDto {
val member = userUtil.fetchCurrentUser()
Expand Down Expand Up @@ -48,11 +50,18 @@ class ToggleMusicLikeServiceImpl(
)
musicLikeRepository.save(musicLike)
music.plusLikeCount()
updateCache(music)
}

private fun deleteLike (likeId: Long, music: Music) {
musicLikeRepository.deleteById(likeId)
music.minusLikeCount()
updateCache(music)
}

private fun updateCache(music: Music) {
val cacheKey = music.createdDate.toLocalDate().toString()
redisCacheService.deleteFromCacheMusic(cacheKey)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class RedisCacheService(
return redisTemplate.opsForValue().get("musicList:$date")
}

fun deleteFromCacheMusic(date: String) {
redisTemplate.delete("musicList:$date")
}

fun updateCacheFromProfile(memberId: Long, uploadFile: String?) {
updateMemberCache(memberId) { it.copy(profileImage = uploadFile) }
}
Expand Down

0 comments on commit 9ba1cd2

Please sign in to comment.