aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-11-12 13:45:33 -0500
committerLuke <luke.pulverenti@gmail.com>2015-11-12 13:45:33 -0500
commit5571bc98f3353c538e82086cb956d6b2219f9276 (patch)
treea7ebf43b2f13162f584d01c5f21f477398502145 /MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
parent9e4e443253076919f17ab736dff77f87b66b05ee (diff)
parentb5a7483fcc7504b90cac133f5432ab89148b2ae3 (diff)
Merge pull request #1259 from MediaBrowser/master
merge from master
Diffstat (limited to 'MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs')
-rw-r--r--MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs54
1 files changed, 11 insertions, 43 deletions
diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
index 5908cd800..054c5aaaf 100644
--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
@@ -187,20 +187,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
}
/// <summary>
- /// The _semaphoreLocks
- /// </summary>
- private readonly ConcurrentDictionary<string, SemaphoreSlim> _semaphoreLocks = new ConcurrentDictionary<string, SemaphoreSlim>(StringComparer.OrdinalIgnoreCase);
- /// <summary>
- /// Gets the lock.
- /// </summary>
- /// <param name="url">The filename.</param>
- /// <returns>System.Object.</returns>
- private SemaphoreSlim GetLock(string url)
- {
- return _semaphoreLocks.GetOrAdd(url, key => new SemaphoreSlim(1, 1));
- }
-
- /// <summary>
/// Gets the response internal.
/// </summary>
/// <param name="options">The options.</param>
@@ -270,7 +256,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
var url = options.Url;
var urlHash = url.ToLower().GetMD5().ToString("N");
-
+
var responseCachePath = Path.Combine(_appPaths.CachePath, "httpclient", urlHash);
response = await GetCachedResponse(responseCachePath, options.CacheLength, url).ConfigureAwait(false);
@@ -279,31 +265,14 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
return response;
}
- var semaphore = GetLock(url);
-
- await semaphore.WaitAsync(options.CancellationToken).ConfigureAwait(false);
-
- try
- {
- response = await GetCachedResponse(responseCachePath, options.CacheLength, url).ConfigureAwait(false);
- if (response != null)
- {
- return response;
- }
-
- response = await SendAsyncInternal(options, httpMethod).ConfigureAwait(false);
+ response = await SendAsyncInternal(options, httpMethod).ConfigureAwait(false);
- if (response.StatusCode == HttpStatusCode.OK)
- {
- await CacheResponse(response, responseCachePath).ConfigureAwait(false);
- }
-
- return response;
- }
- finally
+ if (response.StatusCode == HttpStatusCode.OK)
{
- semaphore.Release();
+ await CacheResponse(response, responseCachePath).ConfigureAwait(false);
}
+
+ return response;
}
private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
@@ -348,13 +317,12 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
using (var responseStream = response.Content)
{
- using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
- {
- var memoryStream = new MemoryStream();
+ var memoryStream = new MemoryStream();
+ await responseStream.CopyToAsync(memoryStream).ConfigureAwait(false);
+ memoryStream.Position = 0;
- await responseStream.CopyToAsync(memoryStream).ConfigureAwait(false);
-
- memoryStream.Position = 0;
+ using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileMode.Create, FileAccess.Write, FileShare.None, true))
+ {
await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false);
memoryStream.Position = 0;