All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.bjoernpetersen.musicbot.internal.auth.CachedRefreshClaimDatabase.kt Maven / Gradle / Ivy

There is a newer version: 0.25.0
Show newest version
package net.bjoernpetersen.musicbot.internal.auth

import com.google.common.cache.CacheBuilder
import com.google.common.cache.LoadingCache
import net.bjoernpetersen.musicbot.api.cache.cacheLoader

private const val MAX_SIZE = 2048L
private const val INIT_CAPACITY = 64

internal class CachedRefreshClaimDatabase(
    private val delegate: RefreshClaimDatabase
) : RefreshClaimDatabase {
    private val cache: LoadingCache = CacheBuilder.newBuilder()
        .maximumSize(MAX_SIZE)
        .initialCapacity(INIT_CAPACITY)
        .build(cacheLoader(delegate::getClaim))

    override fun getClaim(userId: String): String {
        return cache[userId]
    }

    override fun invalidateClaim(userId: String) {
        cache.invalidate(userId)
        delegate.invalidateClaim(userId)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy