/// <summary>
 /// Constructs a garbage collector for the Firestore distributed cache.
 /// </summary>
 /// <param name="cache">The cache to garbage collect. Must not be null.</param>
 /// <param name="logger">The logger to use for diagnostic messages. Must not be null.</param>
 /// <param name="frequency">The frequency of garbage collection. May be null, in which case a default frequency of 1 day will be used.</param>
 /// <param name="scheduler">The scheduler to use. May be null, in which case the system scheduler will be used.</param>
 public FirestoreCacheGarbageCollector(FirestoreCache cache,
                                       ILogger <FirestoreCacheGarbageCollector> logger,
                                       TimeSpan?frequency = null, Api.Gax.IScheduler scheduler = null)
 {
     _cache     = GaxPreconditions.CheckNotNull(cache, nameof(cache));
     _logger    = GaxPreconditions.CheckNotNull(logger, nameof(logger));
     _frequency = frequency.GetValueOrDefault(TimeSpan.FromDays(1));
     _scheduler = scheduler ?? SystemScheduler.Instance;
 }
 /// <summary>
 /// Add a distributed cache that stores cache entries in Firestore.
 /// </summary>
 /// <param name="services">The service collection to which to add the cache.</param>
 /// <param name="projectId">Your Google Cloud Project Id.
 /// If null, pulls your project id from the current application
 /// default credentials.
 /// </param>
 public static IServiceCollection AddFirestoreDistributedCache(
     this IServiceCollection services,
     string projectId = null)
 {
     services.AddSingleton <FirestoreCache>(provider =>
                                            new FirestoreCache(projectId ?? FirestoreCache.GetProjectId(),
                                                               provider.GetService <ILogger <FirestoreCache> >()));
     services.AddSingleton <IDistributedCache>(provider =>
                                               provider.GetService <FirestoreCache>());
     return(services);
 }