Check if file exists instead of catching exceptions

This commit is contained in:
Bond_009
2019-01-27 17:00:17 +01:00
parent 1a3543e5a5
commit ffe79c8982
6 changed files with 73 additions and 99 deletions

View File

@@ -286,28 +286,18 @@ namespace Emby.Server.Implementations.HttpClientManager
private HttpResponseInfo GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
{
try
if (File.Exists(responseCachePath)
&& _fileSystem.GetLastWriteTimeUtc(responseCachePath).Add(cacheLength) > DateTime.UtcNow)
{
if (_fileSystem.GetLastWriteTimeUtc(responseCachePath).Add(cacheLength) > DateTime.UtcNow)
var stream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read, true);
return new HttpResponseInfo
{
var stream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read, true);
return new HttpResponseInfo
{
ResponseUrl = url,
Content = stream,
StatusCode = HttpStatusCode.OK,
ContentLength = stream.Length
};
}
}
catch (FileNotFoundException) // REVIEW: @bond Is this really faster?
{
}
catch (DirectoryNotFoundException)
{
ResponseUrl = url,
Content = stream,
StatusCode = HttpStatusCode.OK,
ContentLength = stream.Length
};
}
return null;