

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

# 輸入 Cache
<a name="retrieving-secrets_cache-go_cache"></a>

從 Secrets Manager 請求的秘密記憶體內快取。您使用 [GetSecretString](#retrieving-secrets_cache-go_cache_operations_GetCachedSecret) 或 [GetSecretBinary](#retrieving-secrets_cache-go_cache_operations_GetSecretBinary) 從快取中擷取秘密。

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

```
// 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 秘密值](retrieving-secrets_cache-go.md)。

## 方法
<a name="retrieving-secrets_cache-go_cache_operations"></a>

### 新增
<a name="retrieving-secrets_cache-go_cache_operations_New"></a>

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

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

### GetSecretString
<a name="retrieving-secrets_cache-go_cache_operations_GetCachedSecret"></a>

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

GetSecretString 從快取中取得秘密字串值，用於指定秘密 ID。如果操作失敗，傳回秘密字串和錯誤。

### GetSecretStringWithStage
<a name="retrieving-secrets_cache-go_cache_operations_GetSecretStringWithStage"></a>

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

GetSecretStringWithStage 從快取中取得秘密字串值，用於指定秘密 ID 和[版本階段](whats-in-a-secret.md#term_version)。如果操作失敗，傳回秘密字串和錯誤。

### GetSecretBinary
<a name="retrieving-secrets_cache-go_cache_operations_GetSecretBinary"></a>

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

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

### GetSecretBinaryWithStage
<a name="retrieving-secrets_cache-go_cache_operations_GetSecretBinaryWithStage"></a>

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

GetSecretBinaryWithStage 從快取中取得秘密二進位值，用於指定秘密 ID 和[版本階段](whats-in-a-secret.md#term_version)。如果操作失敗，則傳回秘密二進位和錯誤。