com.atlan.pkg.cache.ChecksumCache.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of package-toolkit-runtime Show documentation
Show all versions of package-toolkit-runtime Show documentation
Atlan custom package runtime toolkit
/* SPDX-License-Identifier: Apache-2.0
Copyright 2024 Atlan Pte. Ltd. */
package com.atlan.pkg.cache
import com.atlan.cache.AbstractOffHeapCache
import com.atlan.util.AssetBatch.AssetIdentity
import java.nio.charset.StandardCharsets
/**
* Generic class through which to cache any objects efficiently, off-heap, to avoid risking extreme
* memory usage.
*/
class ChecksumCache(
name: String?,
) : AbstractOffHeapCache(name) {
/** {@inheritDoc} */
override fun serializeKey(key: AssetIdentity): ByteArray {
return key.toString().toByteArray(StandardCharsets.UTF_8)
}
/** {@inheritDoc} */
override fun deserializeKey(bytes: ByteArray): AssetIdentity {
return AssetIdentity.fromString(String(bytes, StandardCharsets.UTF_8))
}
/** {@inheritDoc} */
override fun serializeValue(value: String): ByteArray {
return value.toByteArray(StandardCharsets.UTF_8)
}
/** {@inheritDoc} */
override fun deserializeValue(bytes: ByteArray): String {
return String(bytes, StandardCharsets.UTF_8)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy