public TzdbDownload?GetRelease(string name) { var releasesByName = (cache.Value ?? FetchReleases()).ReleasesByName; if (releasesByName.TryGetValue(name, out var value)) { return(value); } // We don't know about the requested release from the last cache refresh. See whether // it's *possibly* a real release, and if so try to fetch the object metadata. // If that succeeds, serve that (and remember it) until we next refresh the cache. if (!PlausibleReleaseName.IsMatch(name)) { return(null); } var onDemandCache = cache.Value?.OnDemandReleasesByName ?? new ConcurrentDictionary <string, TzdbDownload>(); if (onDemandCache.TryGetValue(name, out value)) { return(value); } string objectName = $"tzdb/{name}"; try { storage.GetObject(objectName); } catch (GoogleApiException) { // If we can't get the metadata entry for *any* reason, just return that it's not been found. return(null); } value = new TzdbDownload(storage, objectName); onDemandCache[name] = value; return(value); }
private string GetDownloadUrl(TzdbDownload download) => $"{Request.Scheme}://{Request.Host}/tzdb/{download.Name}";