SecretCache - AWS Secrets Manager

SecretCache

An in-memory cache for secrets requested from Secrets Manager. You use getSecretString or getSecretBinary to retrieve a secret from the cache. You can configure the cache settings by passing in a SecretCacheConfiguration object in the constructor.

For more information, including examples, see Get a Secrets Manager secret value using Java with client-side caching.

Constructors

public SecretCache()

Default constructor for a SecretCache object.

public SecretCache(AWSSecretsManagerClientBuilder builder)

Constructs a new cache using a Secrets Manager client created using the provided AWSSecretsManagerClientBuilder. Use this constructor to customize the Secrets Manager client, for example to use a specific Region or endpoint.

public SecretCache(AWSSecretsManager client)

Constructs a new secret cache using the provided AWSSecretsManagerClient. Use this constructor to customize the Secrets Manager client, for example to use a specific Region or endpoint.

public SecretCache(SecretCacheConfiguration config)

Constructs a new secret cache using the provided SecretCacheConfiguration.

Methods

getSecretString

public String getSecretString(final String secretId)

Retrieves a string secret from Secrets Manager. Returns a String.

getSecretBinary

public ByteBuffer getSecretBinary(final String secretId)

Retrieves a binary secret from Secrets Manager. Returns a ByteBuffer.

refreshNow

public boolean refreshNow(final String secretId) throws InterruptedException

Forces the cache to refresh. Returns true if the refresh completed without error, otherwise false.

close

public void close()

Closes the cache.