Пример #1
0
        public async Task <string> GetSecretAsync(string secretName, bool ignoreCache)
        {
            // Check if the secret is already cached, return it if it is
            if (ignoreCache == false && memoryCache.TryGetValue(secretName, out string secretValue))
            {
                telemetryProvider.IncreaseGauge("Cache Hit");
                telemetryProvider.LogTrace($"Secret '{secretName}' cached");
                return(secretValue);
            }

            // Fetch latest secret from Key Vault
            var secret = await secretProvider.GetSecretAsync(secretName);

            // Store found secret in memory cache
            telemetryProvider.IncreaseGauge("Cache Miss");
            telemetryProvider.LogTrace($"Secret '{secretName}' was not cached");
            memoryCache.Set(secretName, secret, defaultCacheExpiryDuration);

            return(secret);
        }