

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

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

Un cache en mémoire pour les secrets demandés à Secrets Manager. Vous utilisez [GetSecretString](#retrieving-secrets_cache-go_cache_operations_GetCachedSecret) ou [GetSecretBinary](#retrieving-secrets_cache-go_cache_operations_GetSecretBinary) pour récupérer un secret du cache. 

L'exemple suivant montre comment configurer les paramètres du cache.

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

Pour plus d'informations, ainsi que pour voir des exemples, consultez [Obtenez une valeur secrète de Secrets Manager à l'aide de Go avec la mise en cache côté client](retrieving-secrets_cache-go.md).

## Méthodes
<a name="retrieving-secrets_cache-go_cache_operations"></a>

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

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

New construit un cache secret à l'aide d'options fonctionnelles, sinon il utilise les valeurs par défaut. Initialise un SecretsManager client à partir d'une nouvelle session. S'initialise CacheConfig aux valeurs par défaut. Initialise le cache LRU avec une taille maximale par défaut.

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

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

GetSecretString obtient la valeur de la chaîne secrète du cache pour un ID secret donné. Renvoie la chaîne secrète et une erreur en cas d'échec de l'opération.

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

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

GetSecretStringWithStage obtient la valeur de la chaîne secrète du cache pour un ID secret et une [étape de version](whats-in-a-secret.md#term_version) donnés. Renvoie la chaîne secrète et une erreur en cas d'échec de l'opération.

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

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

GetSecretBinary obtient la valeur binaire secrète du cache pour un identifiant secret donné. Renvoie le binaire secret et une erreur si l'opération a échoué.

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

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

GetSecretBinaryWithStage obtient la valeur binaire secrète du cache pour un ID secret et une [étape de version](whats-in-a-secret.md#term_version) donnés. Renvoie le binaire secret et une erreur si l'opération a échoué. 