diff --git a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/utils/DiscordGuildCache.kt b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/utils/DiscordGuildCache.kt index f2e1f1f..7bd0eff 100644 --- a/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/utils/DiscordGuildCache.kt +++ b/webserver/src/main/kotlin/space/mori/chzzk_bot/webserver/utils/DiscordGuildCache.kt @@ -15,15 +15,13 @@ object DiscordGuildCache { private val cache = ConcurrentHashMap() private const val EXP_SECONDS = 600L - suspend fun getCachedGuilds(guildId: String): Guild? { + private suspend fun getCachedGuilds(guildId: String): Guild? { val now = Instant.now() - return if(cache.isNotEmpty() && cache[guildId]?.timestamp?.plusSeconds(EXP_SECONDS)?.isAfter(now) == false) { - cache[guildId]?.guild - } else { + if(cache.isEmpty() || !cache.containsKey(guildId) || cache[guildId]!!.timestamp.plusSeconds(EXP_SECONDS).isBefore(now)) { fetchAllGuilds() - cache[guildId]?.guild } + return cache[guildId]?.guild } suspend fun getCachedGuilds(guildId: List): List {