mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 07:18:22 +00:00
asdf3
This commit is contained in:
parent
4d0345be9e
commit
1679d8cd18
@ -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> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user