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

secretblob.SecretBlobCacheDecorator.kt Maven / Gradle / Ivy

There is a newer version: 0.3.1
Show newest version
package se.wollan.crypto.secretblob

import java.util.concurrent.ConcurrentHashMap

internal class SecretBlobCacheDecorator(private val inner: SecretBlob, keys: List) : SecretBlob {
    private val cache = ConcurrentHashMap(keys.size)

    override fun getSecretDataForKey(key: SecretBlobKey): ByteArray {
        cache[key]?.let { return it.copyOf() }

        val data = inner.getSecretDataForKey(key)

        // no need to copy here as no one is holding a reference to data according to the contract of getSecretDataForKey
        cache[key] = data

        return data.copyOf()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy