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

com.atlan.pkg.cache.ChecksumCache.kt Maven / Gradle / Ivy

There is a newer version: 3.1.2
Show newest version
/* 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