aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-02-03 23:04:19 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-02-03 23:04:19 -0500
commit351cfef7a70ef311801be0bc9eb9e3891265d22b (patch)
treeedb841c6b311a1c13c4c70cbd4ed08e9129fac78 /MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs
parent48b9f657a4d163e4be32c1641907fc429481aa85 (diff)
use conditional caching on some json responses
Diffstat (limited to 'MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs')
-rw-r--r--MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs34
1 files changed, 22 insertions, 12 deletions
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
/// </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);
+ }
}
} \ No newline at end of file