public bool TryDownloadAndSaveObject(string firstTwoShaDigits, string remainingShaDigits) { DateTime negativeCacheRequestTime; string objectId = firstTwoShaDigits + remainingShaDigits; if (this.objectNegativeCache.TryGetValue(objectId, out negativeCacheRequestTime)) { if (negativeCacheRequestTime > DateTime.Now.Subtract(NegativeCacheTTL)) { return(false); } this.objectNegativeCache.TryRemove(objectId, out negativeCacheRequestTime); } DownloadAndSaveObjectResult result = this.TryDownloadAndSaveObject(objectId); switch (result) { case DownloadAndSaveObjectResult.Success: return(true); case DownloadAndSaveObjectResult.ObjectNotOnServer: this.objectNegativeCache.AddOrUpdate(objectId, DateTime.Now, (unused1, unused2) => DateTime.Now); return(false); case DownloadAndSaveObjectResult.Error: return(false); default: throw new InvalidOperationException("Unknown DownloadAndSaveObjectResult value"); } }
protected override DownloadAndSaveObjectResult TryDownloadAndSaveObject(string objectId, CancellationToken cancellationToken, bool retryOnFailure) { DateTime negativeCacheRequestTime; if (this.objectNegativeCache.TryGetValue(objectId, out negativeCacheRequestTime)) { if (negativeCacheRequestTime > DateTime.Now.Subtract(NegativeCacheTTL)) { return(DownloadAndSaveObjectResult.ObjectNotOnServer); } this.objectNegativeCache.TryRemove(objectId, out negativeCacheRequestTime); } DownloadAndSaveObjectResult result = base.TryDownloadAndSaveObject(objectId, cancellationToken, retryOnFailure); if (result == DownloadAndSaveObjectResult.ObjectNotOnServer) { this.objectNegativeCache.AddOrUpdate(objectId, DateTime.Now, (unused1, unused2) => DateTime.Now); } return(result); }