Merge pull request #1259 from MediaBrowser/master

merge from master
This commit is contained in:
Luke 2015-11-12 13:45:33 -05:00
commit 5571bc98f3
4 changed files with 14 additions and 56 deletions

View File

@ -186,20 +186,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>
@ -279,18 +265,6 @@ 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);
if (response.StatusCode == HttpStatusCode.OK)
@ -300,11 +274,6 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
return response;
}
finally
{
semaphore.Release();
}
}
private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
{
@ -347,14 +316,13 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
_fileSystem.CreateDirectory(Path.GetDirectoryName(responseCachePath));
using (var responseStream = response.Content)
{
using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
{
var memoryStream = new MemoryStream();
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;

View File

@ -297,12 +297,6 @@ namespace MediaBrowser.Providers.Music
ResourcePool = _musicBrainzResourcePool
};
if (!isSearch)
{
options.CacheMode = CacheMode.Unconditional;
options.CacheLength = TimeSpan.FromDays(3);
}
using (var xml = await _httpClient.Get(options).ConfigureAwait(false))
{
using (var oReader = new StreamReader(xml, Encoding.UTF8))

View File

@ -99,9 +99,7 @@ namespace MediaBrowser.Providers.Omdb
{
Url = url,
ResourcePool = OmdbProvider.ResourcePool,
CancellationToken = cancellationToken,
CacheMode = CacheMode.Unconditional,
CacheLength = TimeSpan.FromDays(2)
CancellationToken = cancellationToken
}).ConfigureAwait(false))
{

View File

@ -43,9 +43,7 @@ namespace MediaBrowser.Providers.Omdb
{
Url = url,
ResourcePool = ResourcePool,
CancellationToken = cancellationToken,
CacheMode = CacheMode.Unconditional,
CacheLength = TimeSpan.FromDays(7)
CancellationToken = cancellationToken
}).ConfigureAwait(false))
{