type Cache - AWS Secrets Manager

type Cache

An in-memory cache for secrets requested from Secrets Manager. You use GetSecretString or GetSecretBinary to retrieve a secret from the cache.

The following example shows how to configure the cache settings.

// Create a custom secretsmanager client client := getCustomClient() // Create a custom CacheConfig struct config := secretcache. CacheConfig{ MaxCacheSize: secretcache.DefaultMaxCacheSize + 10, VersionStage: secretcache.DefaultVersionStage, CacheItemTTL: secretcache.DefaultCacheItemTTL, } // Instantiate the cache cache, _ := secretcache.New( func( c *secretcache.Cache) { c. CacheConfig = config }, func( c *secretcache.Cache) { c. Client = client }, )

For more information, including examples, see Retrieve AWS Secrets Manager secrets in Go applications.

Methods

New

func New(optFns ...func(*Cache)) (*Cache, error)

New constructs a secret cache using functional options, uses defaults otherwise. Initializes a SecretsManager Client from a new session. Initializes CacheConfig to default values. Initialises LRU cache with a default max size.

GetSecretString

func (c *Cache) GetSecretString(secretId string) (string, error)

GetSecretString gets the secret string value from the cache for given secret ID. Returns the secret sting and an error if operation failed.

GetSecretStringWithStage

func (c *Cache) GetSecretStringWithStage(secretId string, versionStage string) (string, error)

GetSecretStringWithStage gets the secret string value from the cache for given secret ID and version stage. Returns the secret sting and an error if operation failed.

GetSecretBinary

func (c *Cache) GetSecretBinary(secretId string) ([]byte, error) {

GetSecretBinary gets the secret binary value from the cache for given secret ID. Returns the secret binary and an error if operation failed.

GetSecretBinaryWithStage

func (c *Cache) GetSecretBinaryWithStage(secretId string, versionStage string) ([]byte, error)

GetSecretBinaryWithStage gets the secret binary value from the cache for given secret ID and version stage. Returns the secret binary and an error if operation failed.