File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
application/src/main/kotlin/com/pokit/user/port/service Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -117,8 +117,11 @@ class UserService(
117117 }
118118
119119 override fun getUserInfo (userId : Long ): User {
120- return userCachePort.loadById(userId)
121- ? : userPort.loadById(userId)?.also { userCachePort.persist(it) }
120+ cacheOrNull { userCachePort.loadById(userId) }
121+ ?.let { return it }
122+
123+ return userPort.loadById(userId)
124+ ?.also { tryCachePersist(it) }
122125 ? : throw NotFoundCustomException (UserErrorCode .NOT_FOUND_USER )
123126 }
124127
@@ -161,4 +164,12 @@ class UserService(
161164 interestPort.persist(Interest (userId = userId, interestType = it))
162165 }
163166 }
167+
168+ // redis fallback
169+ private inline fun <T > cacheOrNull (block : () -> T ? ): T ? =
170+ runCatching(block).getOrNull()
171+
172+ private fun tryCachePersist (user : User ) {
173+ runCatching { userCachePort.persist(user) }
174+ }
164175}
You can’t perform that action at this time.
0 commit comments