public static void TrySavingTopologyToLocalCache(string serverHash, ClusterTopologyResponse clusterTopology, JsonOperationContext context)
        {
            try
            {
                var path = GetClusterTopologyPath(serverHash);
                if (clusterTopology == null)
                {
                    ClearTopologyFromLocalCache(serverHash);
                    return;
                }

                using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                    using (var writer = new BlittableJsonTextWriter(context, stream))
                    {
                        var json = new DynamicJsonValue
                        {
                            [nameof(clusterTopology.Topology)] = clusterTopology.Topology.ToJson(),
                            [nameof(clusterTopology.Leader)]   = clusterTopology.Leader,
                            [nameof(clusterTopology.NodeTag)]  = clusterTopology.NodeTag
                        };

                        context.Write(writer, json);
                        writer.Flush();
                    }
            }
            catch (Exception e)
            {
                if (_logger.IsInfoEnabled)
                {
                    _logger.Info("Could not persist the replication information", e);
                }
            }
        }
        public static void TrySaving(string topologyHash, ClusterTopologyResponse clusterTopology, JsonOperationContext context)
        {
            try
            {
                var path = GetPath(topologyHash);
                if (clusterTopology == null)
                {
                    Clear(path);
                    return;
                }

                using (var stream = SafeFileStream.Create(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                    using (var writer = new BlittableJsonTextWriter(context, stream))
                    {
                        var json = new DynamicJsonValue
                        {
                            [nameof(clusterTopology.Topology)] = clusterTopology.Topology.ToJson(),
                            [nameof(clusterTopology.Leader)]   = clusterTopology.Leader,
                            [nameof(clusterTopology.NodeTag)]  = clusterTopology.NodeTag,
                            ["PersistedAt"] = DateTimeOffset.UtcNow.ToString(DefaultFormat.DateTimeOffsetFormatsToWrite),
                        };

                        context.Write(writer, json);
                        writer.Flush();
                    }
            }
            catch (Exception e)
            {
                if (_logger.IsInfoEnabled)
                {
                    _logger.Info("Could not persist the cluster topology", e);
                }
            }
        }
        public static async Task TrySavingAsync(string topologyHash, ClusterTopologyResponse clusterTopology, DocumentConventions conventions, JsonOperationContext context, CancellationToken token)
        {
            try
            {
                if (conventions.DisableTopologyCache)
                {
                    return;
                }

                var path = GetPath(topologyHash, conventions);
                if (clusterTopology == null)
                {
                    Clear(path);
                    return;
                }

                using (var stream = SafeFileStream.Create(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                    await using (var writer = new AsyncBlittableJsonTextWriter(context, stream))
                    {
                        var json = new DynamicJsonValue
                        {
                            [nameof(clusterTopology.Topology)] = clusterTopology.Topology.ToJson(),
                            [nameof(clusterTopology.Leader)]   = clusterTopology.Leader,
                            [nameof(clusterTopology.NodeTag)]  = clusterTopology.NodeTag,
                            [nameof(clusterTopology.Etag)]     = clusterTopology.Etag,
                            ["PersistedAt"] = DateTimeOffset.UtcNow.ToString(DefaultFormat.DateTimeOffsetFormatsToWrite),
                        };

                        context.Write(writer, json);
                        await writer.FlushAsync(token).ConfigureAwait(false);
                    }
            }
            catch (Exception e)
            {
                if (_logger.IsInfoEnabled)
                {
                    _logger.Info("Could not persist the cluster topology", e);
                }
            }
        }