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

tech.carcadex.kotlinbukkitkit.exposed.delegate.Cached.kt Maven / Gradle / Ivy

The newest version!
package tech.carcadex.kotlinbukkitkit.exposed.delegate

import org.jetbrains.exposed.dao.Entity
import kotlin.reflect.KProperty

public fun  ExposedDelegate.cached(): ExposedDelegate = CachedExposedDelegate(this)

public class CachedExposedDelegate(
    private val delegate: ExposedDelegate,
) : ExposedDelegate {
    private var cache: T? = null
    private var isCached: Boolean = false

    override fun > getValue(
        entity: Entity,
        desc: KProperty<*>,
    ): T {
        if (!isCached) {
            cache = delegate.getValue(entity, desc)
            isCached = true
        }

        return cache!!
    }

    override fun > setValue(
        entity: Entity,
        desc: KProperty<*>,
        value: T,
    ) {
        delegate.setValue(entity, desc, value)
        cache = value
        isCached = true
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy