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

com.aliyuncs.kms.secretsmanager.client.cache.MemoryCacheSecretStoreStrategy Maven / Gradle / Ivy

package com.aliyuncs.kms.secretsmanager.client.cache;

import com.aliyuncs.kms.secretsmanager.client.exception.CacheSecretException;
import com.aliyuncs.kms.secretsmanager.client.model.CacheSecretInfo;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 内存缓存Secret实现
 */
public class MemoryCacheSecretStoreStrategy implements CacheSecretStoreStrategy {

    private final Map cacheSecretInfoMap = new ConcurrentHashMap<>();

    @Override
    public void init() throws CacheSecretException {
        // do nothing
    }

    @Override
    public void storeSecret(CacheSecretInfo cacheSecretInfo) {
        cacheSecretInfoMap.put(cacheSecretInfo.getSecretInfo().getSecretName(), cacheSecretInfo);
    }

    @Override
    public CacheSecretInfo getCacheSecretInfo(String secretName) {
        return cacheSecretInfoMap.get(secretName);
    }

    @Override
    public void close() throws IOException {
        if (cacheSecretInfoMap != null) {
            cacheSecretInfoMap.clear();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy