Class AwsSecretCache

java.lang.Object
codes.grow.packages.awssecretsmanager.AwsSecretCache

public final class AwsSecretCache extends Object
Version-stage aware secret cache with the semantics of the AWS caching clients ( aws-secretsmanager-caching-*, DECISIONS.md #3): entries per (secretId, versionStage), default TTL 1 h and 1 024 entries (LRU). On expiry DescribeSecret checks whether the stage moved to another version and GetSecretValue runs only when it did. Concurrent reads of the same entry are coalesced. A refresh that fails keeps serving the cached value and retries with exponential backoff (1 s doubling, capped at the TTL); a first read that fails throws.

Create one with AwsSecretsManagerClient.secretCache().

  • Constructor Details

    • AwsSecretCache

      public AwsSecretCache(AwsSecretCache.Source source, AwsSecretCache.Options options)
      Creates a cache in front of a source (usually a client).
      Parameters:
      source - the source
      options - cache options
  • Method Details

    • awsDefaults

      public static SecretCache.Options awsDefaults()
      Returns the AWS caching-client defaults (TTL 1 h, 1 024 entries) as options of the generic SecretCache, which keeps the SPEC defaults otherwise.
      Returns:
      the preset
    • options

      public AwsSecretCache.Options options()
      Returns the options.
      Returns:
      the options
    • getSecretValue

      public AwsSecretValue getSecretValue(String secretId)
      Returns the cached value at the default stage.
      Parameters:
      secretId - name or ARN
      Returns:
      the value
    • getSecretValue

      public AwsSecretValue getSecretValue(String secretId, String versionStage)
      Returns the cached value of secretId at a stage.
      Parameters:
      secretId - name or ARN
      versionStage - stage label
      Returns:
      the value
    • getSecretString

      public String getSecretString(String secretId)
      Returns the value as text (SecretString, or UTF-8 of the binary).
      Parameters:
      secretId - name or ARN
      Returns:
      the text
    • getSecretString

      public String getSecretString(String secretId, String versionStage)
      Returns the value at a stage as text.
      Parameters:
      secretId - name or ARN
      versionStage - stage label
      Returns:
      the text
    • getSecretBinary

      public byte[] getSecretBinary(String secretId)
      Returns the value as bytes.
      Parameters:
      secretId - name or ARN
      Returns:
      the bytes
    • getSecretBinary

      public byte[] getSecretBinary(String secretId, String versionStage)
      Returns the value at a stage as bytes.
      Parameters:
      secretId - name or ARN
      versionStage - stage label
      Returns:
      the bytes
    • refreshNow

      public AwsSecretValue refreshNow(String secretId)
      Forces a refresh check now (and a fetch when the stage moved).
      Parameters:
      secretId - name or ARN
      Returns:
      the value
    • refreshNow

      public AwsSecretValue refreshNow(String secretId, String versionStage)
      Forces a refresh check of a stage now.
      Parameters:
      secretId - name or ARN
      versionStage - stage label
      Returns:
      the value
    • invalidate

      public void invalidate(String secretId)
      Drops every cached stage of secretId.
      Parameters:
      secretId - name or ARN
    • clear

      public void clear()
      Drops every entry.
    • stats

      public AwsSecretCacheStats stats()
      Returns the counters and the current size.
      Returns:
      the statistics