added cache pipelines

This commit is contained in:
kay.one
2013-08-19 22:53:18 -07:00
parent 4183fecaca
commit 290e072f2e
10 changed files with 122 additions and 37 deletions

View File

@@ -1,16 +1,28 @@
using System;
using Nancy;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Api.Frontend
{
public class IsCacheableSpecification
public interface ICacheableSpecification
{
public bool IsCacheable(Request request)
{
if (request.Path.Contains(".")) return false;
if (request.Path.StartsWith("/api", StringComparison.CurrentCultureIgnoreCase)) return false;
if (request.Path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase)) return false;
bool IsCacheable(NancyContext context);
}
public class CacheableSpecification : ICacheableSpecification
{
public bool IsCacheable(NancyContext context)
{
if (context.Request.Query.v == BuildInfo.Version) return true;
if (context.Request.Path.StartsWith("/api", StringComparison.CurrentCultureIgnoreCase)) return false;
if (context.Request.Path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase)) return false;
if (context.Request.Path.EndsWith("app.js")) return false;
if (context.Response != null)
{
if (context.Response.ContentType.Contains("text/html")) return false;
}
return true;
}