This commit is contained in:
dalbodeule 2024-08-14 19:39:47 +09:00
parent 4d0345be9e
commit 1679d8cd18
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65

View File

@ -15,15 +15,13 @@ object DiscordGuildCache {
private val cache = ConcurrentHashMap<String, CachedGuilds>() private val cache = ConcurrentHashMap<String, CachedGuilds>()
private const val EXP_SECONDS = 600L private const val EXP_SECONDS = 600L
suspend fun getCachedGuilds(guildId: String): Guild? { private suspend fun getCachedGuilds(guildId: String): Guild? {
val now = Instant.now() val now = Instant.now()
return if(cache.isNotEmpty() && cache[guildId]?.timestamp?.plusSeconds(EXP_SECONDS)?.isAfter(now) == false) { if(cache.isEmpty() || !cache.containsKey(guildId) || cache[guildId]!!.timestamp.plusSeconds(EXP_SECONDS).isBefore(now)) {
cache[guildId]?.guild
} else {
fetchAllGuilds() fetchAllGuilds()
cache[guildId]?.guild
} }
return cache[guildId]?.guild
} }
suspend fun getCachedGuilds(guildId: List<String>): List<Guild> { suspend fun getCachedGuilds(guildId: List<String>): List<Guild> {