From 351cfef7a70ef311801be0bc9eb9e3891265d22b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 3 Feb 2014 23:04:19 -0500 Subject: use conditional caching on some json responses --- .../EntryPoints/LibraryChangedNotifier.cs | 2 +- .../HttpServer/HttpResultFactory.cs | 34 ++++++++++++++-------- .../IO/LibraryMonitor.cs | 3 +- .../Library/LibraryManager.cs | 7 +++-- 4 files changed, 29 insertions(+), 17 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index bbcc14524..32d4c7708 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -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) { diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs index 9359261c5..3712a58f5 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -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 /// private readonly ILogger _logger; private readonly IFileSystem _fileSystem; + private readonly IJsonSerializer _jsonSerializer; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The log manager. - public HttpResultFactory(ILogManager logManager, IFileSystem fileSystem) + /// The file system. + /// The json serializer. + 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 /// The factory fn. /// The response headers. /// System.Object. - /// - /// cacheKey + /// cacheKey /// or - /// factoryFn - /// - public object GetOptimizedResultUsingCache(IRequest requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func factoryFn, IDictionary responseHeaders = null) + /// factoryFn + public object GetOptimizedResultUsingCache(IRequest requestContext, Guid cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, Func factoryFn, IDictionary responseHeaders = null) where T : class { if (cacheKey == Guid.Empty) @@ -199,7 +200,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// The response headers. /// System.Object. /// cacheKey - public object GetCachedResult(IRequest requestContext, Guid cacheKey, DateTime lastDateModified, TimeSpan? cacheDuration, Func factoryFn, string contentType, IDictionary responseHeaders = null) + public object GetCachedResult(IRequest requestContext, Guid cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, Func factoryFn, string contentType, IDictionary responseHeaders = null) where T : class { if (cacheKey == Guid.Empty) @@ -661,5 +662,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer throw error; } + + public object GetOptimizedSerializedResultUsingCache(IRequest request, T result) + where T : class + { + var json = _jsonSerializer.SerializeToString(result); + var cacheKey = json.GetMD5(); + + return GetOptimizedResultUsingCache(request, cacheKey, null, null, () => result); + } } } \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs index 58141902e..38f5cb62a 100644 --- a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs +++ b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs @@ -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) { diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 1e04f7e09..8294bfed6 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -270,6 +270,7 @@ namespace MediaBrowser.Server.Implementations.Library /// private string _seasonZeroDisplayName; + private bool _wizardCompleted; /// /// Records the configuration values. /// @@ -278,6 +279,7 @@ namespace MediaBrowser.Server.Implementations.Library { _seasonZeroDisplayName = configuration.SeasonZeroDisplayName; _itemsByNamePath = ConfigurationManager.ApplicationPaths.ItemsByNamePath; + _wizardCompleted = configuration.IsStartupWizardCompleted; } /// @@ -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(); } @@ -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) { -- cgit v1.2.3