use conditional caching on some json responses

This commit is contained in:
Luke Pulverenti
2014-02-03 23:04:19 -05:00
parent 48b9f657a4
commit 351cfef7a7
48 changed files with 221 additions and 143 deletions

View File

@@ -279,7 +279,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
try
{
return i.LocationType == LocationType.FileSystem &&
i.ResolveArgs.PhysicalLocations.Contains(item.Path);
i.PhysicalLocations.Contains(item.Path);
}
catch (Exception ex)
{

View File

@@ -1,9 +1,10 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using ServiceStack;
using ServiceStack.Web;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -11,8 +12,6 @@ using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using ServiceStack;
using ServiceStack.Web;
using MimeTypes = MediaBrowser.Common.Net.MimeTypes;
namespace MediaBrowser.Server.Implementations.HttpServer
@@ -27,14 +26,18 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// </summary>
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
private readonly IJsonSerializer _jsonSerializer;
/// <summary>
/// Initializes a new instance of the <see cref="HttpResultFactory"/> class.
/// Initializes a new instance of the <see cref="HttpResultFactory" /> class.
/// </summary>
/// <param name="logManager">The log manager.</param>
public HttpResultFactory(ILogManager logManager, IFileSystem fileSystem)
/// <param name="fileSystem">The file system.</param>
/// <param name="jsonSerializer">The json serializer.</param>
public HttpResultFactory(ILogManager logManager, IFileSystem fileSystem, IJsonSerializer jsonSerializer)
{
_fileSystem = fileSystem;
_jsonSerializer = jsonSerializer;
_logger = logManager.GetLogger("HttpResultFactory");
}
@@ -151,12 +154,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// <param name="factoryFn">The factory fn.</param>
/// <param name="responseHeaders">The response headers.</param>
/// <returns>System.Object.</returns>
/// <exception cref="System.ArgumentNullException">
/// cacheKey
/// <exception cref="System.ArgumentNullException">cacheKey
/// or
/// factoryFn
/// </exception>
public object GetOptimizedResultUsingCache<T>(IRequest requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, IDictionary<string, string> responseHeaders = null)
/// factoryFn</exception>
public object GetOptimizedResultUsingCache<T>(IRequest requestContext, Guid cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, IDictionary<string, string> responseHeaders = null)
where T : class
{
if (cacheKey == Guid.Empty)
@@ -199,7 +200,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
/// <param name="responseHeaders">The response headers.</param>
/// <returns>System.Object.</returns>
/// <exception cref="System.ArgumentNullException">cacheKey</exception>
public object GetCachedResult<T>(IRequest requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, string contentType, IDictionary<string, string> responseHeaders = null)
public object GetCachedResult<T>(IRequest requestContext, Guid cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, Func<T> factoryFn, string contentType, IDictionary<string, string> responseHeaders = null)
where T : class
{
if (cacheKey == Guid.Empty)
@@ -661,5 +662,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer
throw error;
}
public object GetOptimizedSerializedResultUsingCache<T>(IRequest request, T result)
where T : class
{
var json = _jsonSerializer.SerializeToString(result);
var cacheKey = json.GetMD5();
return GetOptimizedResultUsingCache(request, cacheKey, null, null, () => result);
}
}
}

View File

@@ -166,8 +166,7 @@ namespace MediaBrowser.Server.Implementations.IO
{
try
{
// Accessing ResolveArgs could involve file system access
return f.ResolveArgs.PhysicalLocations;
return f.PhysicalLocations;
}
catch (IOException)
{

View File

@@ -270,6 +270,7 @@ namespace MediaBrowser.Server.Implementations.Library
/// </summary>
private string _seasonZeroDisplayName;
private bool _wizardCompleted;
/// <summary>
/// Records the configuration values.
/// </summary>
@@ -278,6 +279,7 @@ namespace MediaBrowser.Server.Implementations.Library
{
_seasonZeroDisplayName = configuration.SeasonZeroDisplayName;
_itemsByNamePath = ConfigurationManager.ApplicationPaths.ItemsByNamePath;
_wizardCompleted = configuration.IsStartupWizardCompleted;
}
/// <summary>
@@ -298,6 +300,7 @@ namespace MediaBrowser.Server.Implementations.Library
var newSeasonZeroName = ConfigurationManager.Configuration.SeasonZeroDisplayName;
var seasonZeroNameChanged = !string.Equals(_seasonZeroDisplayName, newSeasonZeroName, StringComparison.CurrentCulture);
var wizardChanged = config.IsStartupWizardCompleted != _wizardCompleted;
RecordConfigurationValues(config);
@@ -308,7 +311,7 @@ namespace MediaBrowser.Server.Implementations.Library
await UpdateSeasonZeroNames(newSeasonZeroName, CancellationToken.None).ConfigureAwait(false);
}
if (seasonZeroNameChanged || ibnPathChanged)
if (seasonZeroNameChanged || ibnPathChanged || wizardChanged)
{
_taskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>();
}
@@ -1479,7 +1482,7 @@ namespace MediaBrowser.Server.Implementations.Library
try
{
return i.ResolveArgs.PhysicalLocations.Contains(item.Path);
return i.PhysicalLocations.Contains(item.Path);
}
catch (IOException ex)
{