輸入 Cache - AWS Secrets Manager

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

輸入 Cache

從 Secrets Manager 請求的秘密記憶體內快取。您使用 GetSecretStringGetSecretBinary 從快取中擷取秘密。

下列範例顯示如何設定快取設定。

// 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 }, )

如需包含範例的詳細資訊,請參閱 使用 Go 與客戶端緩存獲取秘 Secrets Manager 秘密值

方法

新增

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

使用功能選項建構新秘密快取,否則使用預設值。從新的工作階段初始化 SecretsManager 用戶端。初始化 CacheConfig 為預設值。使用預設的最大大小起始 LRU 快取。

GetSecretString

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

GetSecretString 從快取取得指定秘密 ID 的秘密字串值。如果操作失敗,則傳回秘密字串和錯誤。

GetSecretStringWithStage

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

GetSecretStringWithStage 從快取取得指定秘密 ID 和版本階段的秘密字串值。如果操作失敗,則傳回秘密字串和錯誤。

GetSecretBinary

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

GetSecretBinary 從快取取得指定秘密 ID 的秘密二進位值。如果操作失敗,則傳回秘密二進位和錯誤。

GetSecretBinaryWithStage

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

GetSecretBinaryWithStage 從快取取得指定秘密 ID 和版本階段的秘密二進位值。如果操作失敗,則傳回秘密二進位和錯誤。