Class AwsSecretCache
java.lang.Object
codes.grow.packages.awssecretsmanager.AwsSecretCache
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().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOptions ofAwsSecretCache.static interfaceThe client operations the cache needs. -
Constructor Summary
ConstructorsConstructorDescriptionAwsSecretCache(AwsSecretCache.Source source, AwsSecretCache.Options options) Creates a cache in front of a source (usually a client). -
Method Summary
Modifier and TypeMethodDescriptionstatic SecretCache.OptionsReturns the AWS caching-client defaults (TTL 1 h, 1 024 entries) as options of the genericSecretCache, which keeps the SPEC defaults otherwise.voidclear()Drops every entry.byte[]getSecretBinary(String secretId) Returns the value as bytes.byte[]getSecretBinary(String secretId, String versionStage) Returns the value at a stage as bytes.getSecretString(String secretId) Returns the value as text (SecretString, or UTF-8 of the binary).getSecretString(String secretId, String versionStage) Returns the value at a stage as text.getSecretValue(String secretId) Returns the cached value at the default stage.getSecretValue(String secretId, String versionStage) Returns the cached value ofsecretIdat a stage.voidinvalidate(String secretId) Drops every cached stage ofsecretId.options()Returns the options.refreshNow(String secretId) Forces a refresh check now (and a fetch when the stage moved).refreshNow(String secretId, String versionStage) Forces a refresh check of a stage now.stats()Returns the counters and the current size.
-
Constructor Details
-
AwsSecretCache
Creates a cache in front of a source (usually a client).- Parameters:
source- the sourceoptions- cache options
-
-
Method Details
-
awsDefaults
Returns the AWS caching-client defaults (TTL 1 h, 1 024 entries) as options of the genericSecretCache, which keeps the SPEC defaults otherwise.- Returns:
- the preset
-
options
Returns the options.- Returns:
- the options
-
getSecretValue
Returns the cached value at the default stage.- Parameters:
secretId- name or ARN- Returns:
- the value
-
getSecretValue
Returns the cached value ofsecretIdat a stage.- Parameters:
secretId- name or ARNversionStage- stage label- Returns:
- the value
-
getSecretString
Returns the value as text (SecretString, or UTF-8 of the binary).- Parameters:
secretId- name or ARN- Returns:
- the text
-
getSecretString
Returns the value at a stage as text.- Parameters:
secretId- name or ARNversionStage- stage label- Returns:
- the text
-
getSecretBinary
Returns the value as bytes.- Parameters:
secretId- name or ARN- Returns:
- the bytes
-
getSecretBinary
Returns the value at a stage as bytes.- Parameters:
secretId- name or ARNversionStage- stage label- Returns:
- the bytes
-
refreshNow
Forces a refresh check now (and a fetch when the stage moved).- Parameters:
secretId- name or ARN- Returns:
- the value
-
refreshNow
Forces a refresh check of a stage now.- Parameters:
secretId- name or ARNversionStage- stage label- Returns:
- the value
-
invalidate
Drops every cached stage ofsecretId.- Parameters:
secretId- name or ARN
-
clear
public void clear()Drops every entry. -
stats
Returns the counters and the current size.- Returns:
- the statistics
-