Cache is disabled for json responses.

This commit is contained in:
Keivan Beigi 2013-07-25 14:57:11 -07:00
commit 642207c68d
5 changed files with 40 additions and 8 deletions

View file

@ -32,24 +32,27 @@ namespace NzbDrone.Api.Extensions
public static JsonResponse<TModel> AsResponse<TModel>(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK)
{
return new JsonResponse<TModel>(model, NancySerializer) { StatusCode = statusCode };
var response = new JsonResponse<TModel>(model, NancySerializer) { StatusCode = statusCode };
response.Headers.DisableCache();
return response;
}
public static IDictionary<string, string> DisableCache(this IDictionary<string, string> headers)
{
headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.Add("Pragma", "no-cache");
headers.Add("Expires", "0");
headers["Cache-Control"] = "no-cache, no-store, must-revalidate";
headers["Pragma"] = "no-cache";
headers["Expires"] = "0";
return headers;
}
public static IDictionary<string, string> EnableCache(this IDictionary<string, string> headers)
{
headers.Add("Cache-Control", "max-age=31536000 , public");
headers.Add("Expires", "Sat, 29 Jun 2020 00:00:00 GMT");
headers.Add("Last-Modified", "Sat, 29 Jun 2000 00:00:00 GMT");
headers.Add("Age", "193266");
headers["Cache-Control"] = "max-age=31536000 , public";
headers["Expires"] = "Sat, 29 Jun 2020 00:00:00 GMT";
headers["Last-Modified"] = "Sat, 29 Jun 2000 00:00:00 GMT";
headers["Age"] = "193266";
return headers;
}