private void PutConnection(string key, CachedConnection cached)
        {
            var cacheEntryOptions = new MemoryCacheEntryOptions()
                                    .SetAbsoluteExpiration(_expiration)
                                    .RegisterPostEvictionCallback((k, value, reason, state) =>
            {
                if (!(value is CachedConnection item))
                {
                    return;
                }

                _logger.LogInformation("Disposing of stale cache item (formerly {instance}).", item.Id);
                item.Connection.Dispose();
            });

            _cache.Set(key, cached, cacheEntryOptions);
            _logger.LogInformation("Cached connection created for {instance}.", cached.Id);
        }
        private CachedConnection SetupConnection(string instance)
        {
            _logger.LogInformation("Connecting to {instance} redis instance.", instance);

            var secretId = instance == Primary ?
                           "redis-connection-string-primary" :
                           "redis-connection-string-secondary";

            var secret     = GetSecret(secretId);
            var connection = new CachedConnection(instance, secret.Value);

            if (connection.IsValid())
            {
                return(connection);
            }

            _logger.LogError("Could not get working connection: {connection}", instance);
            return(null);
        }