Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/LibraryManager/Cache/CacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class CacheService : ICacheService
{
private const int DefaultCacheExpiresAfterDays = 1;
private const int MaxConcurrentDownloads = 10;
private const int DownloadAttempts = 5;
private const int DelayBetweenDownloadAttemptsInMs = 1000;

private readonly IWebRequestHandler _requestHandler;

Expand Down Expand Up @@ -83,7 +85,7 @@ private async Task DownloadToFileAsync(string url, string fileName, int attempts
}
}

await Task.Delay(200, cancellationToken).ConfigureAwait(false);
await Task.Delay(DelayBetweenDownloadAttemptsInMs, cancellationToken).ConfigureAwait(false);
}
}

Expand All @@ -93,7 +95,7 @@ private async Task<string> GetResourceAsync(string url, string localFile, int ex

if (!File.Exists(localFile) || File.GetLastWriteTime(localFile) < DateTime.Now.AddDays(-expiration))
{
await DownloadToFileAsync(url, localFile, attempts: 1, cancellationToken: cancellationToken).ConfigureAwait(false);
await DownloadToFileAsync(url, localFile, DownloadAttempts, cancellationToken: cancellationToken).ConfigureAwait(false);
}

return await FileHelpers.ReadFileAsTextAsync(localFile, cancellationToken).ConfigureAwait(false);
Expand All @@ -111,7 +113,7 @@ async Task DownloadFileIfNecessaryAsync(CacheFileMetadata metadata)
if (!File.Exists(metadata.DestinationPath))
{
logger.Log(string.Format(Resources.Text.DownloadingFile, metadata.Source), LogLevel.Operation);
await DownloadToFileAsync(metadata.Source, metadata.DestinationPath, attempts: 5, cancellationToken: cancellationToken).ConfigureAwait(false);
await DownloadToFileAsync(metadata.Source, metadata.DestinationPath, DownloadAttempts, cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Expand Down