Class SecretCache

java.lang.Object
com.amazonaws.secretsmanager.caching.SecretCache
All Implemented Interfaces:
AutoCloseable

public class SecretCache extends Object implements AutoCloseable
Provides the primary entry-point to the AWS Secrets Manager client cache SDK. Most people will want to use either getSecretString(String) or getSecretBinary(String) to retrieve a secret from the cache.

The core concepts (and classes) in this SDK are:

SecretCache provides an in-memory cache for secrets requested from AWS Secrets Manager.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new secret cache using the standard AWS Secrets Manager client with default options.
    Constructs a new secret cache using the provided cache configuration.
    SecretCache(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient client)
    Constructs a new secret cache using the provided AWS Secrets Manager client.
    SecretCache(software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder builder)
    Constructs a new secret cache using an AWS Secrets Manager client created using the provided builder.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Method to close the cache.
    Method to retrieve a binary secret from AWS Secrets Manager.
    Method to retrieve a string secret from AWS Secrets Manager.
    boolean
    refreshNow(String secretId)
    Method to force the refresh of a cached secret state.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SecretCache

      public SecretCache()
      Constructs a new secret cache using the standard AWS Secrets Manager client with default options.
    • SecretCache

      public SecretCache(software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder builder)
      Constructs a new secret cache using an AWS Secrets Manager client created using the provided builder.
      Parameters:
      builder - The builder to use for creating the AWS Secrets Manager client.
    • SecretCache

      public SecretCache(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient client)
      Constructs a new secret cache using the provided AWS Secrets Manager client.
      Parameters:
      client - The AWS Secrets Manager client to use for requesting secret values.
    • SecretCache

      public SecretCache(SecretCacheConfiguration config)
      Constructs a new secret cache using the provided cache configuration.
      Parameters:
      config - The secret cache configuration.
  • Method Details

    • getSecretString

      public String getSecretString(String secretId)
      Method to retrieve a string secret from AWS Secrets Manager.
      Parameters:
      secretId - The identifier for the secret being requested.
      Returns:
      The string secret
    • getSecretBinary

      public ByteBuffer getSecretBinary(String secretId)
      Method to retrieve a binary secret from AWS Secrets Manager.
      Parameters:
      secretId - The identifier for the secret being requested.
      Returns:
      The binary secret
    • refreshNow

      public boolean refreshNow(String secretId) throws InterruptedException
      Method to force the refresh of a cached secret state.
      Parameters:
      secretId - The identifier for the secret being refreshed.
      Returns:
      True if the refresh completed without error.
      Throws:
      InterruptedException - If the thread is interrupted while waiting for the refresh.
    • close

      public void close()
      Method to close the cache.
      Specified by:
      close in interface AutoCloseable