Fixes: U4-3606 Handle caching issues from server requests correctly
This commit is contained in:
@@ -83,6 +83,27 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return nodeDto == null ? 0 : nodeDto.NodeId;
|
||||
}
|
||||
|
||||
//This should be used later to do GetAll properly without individual selections
|
||||
private IEnumerable<Tuple<int, string>> GetStylesheetIds(string[] paths)
|
||||
{
|
||||
var sql = new Sql()
|
||||
.Select("*")
|
||||
.From<NodeDto>()
|
||||
.Where("nodeObjectType = @NodeObjectType AND umbracoNode.text in (@aliases)",
|
||||
new
|
||||
{
|
||||
NodeObjectType = UmbracoObjectTypes.Stylesheet.GetGuid(),
|
||||
aliases = paths.Select(x => x.TrimEnd(".css").Replace("\\", "/")).ToArray()
|
||||
});
|
||||
var dtos = _dbwork.Database.Fetch<NodeDto>(sql);
|
||||
|
||||
return dtos.Select(x => new Tuple<int, string>(
|
||||
//the id
|
||||
x.NodeId,
|
||||
//the original path requested for the id
|
||||
paths.First(p => p.TrimEnd(".css").Replace("\\", "/") == x.Text)));
|
||||
}
|
||||
|
||||
public override IEnumerable<Stylesheet> GetAll(params string[] ids)
|
||||
{
|
||||
if (ids.Any())
|
||||
|
||||
@@ -63,7 +63,7 @@ function stylesheetResource($q, $http, umbRequestHelper) {
|
||||
umbRequestHelper.getApiUrl(
|
||||
"stylesheetApiBaseUrl",
|
||||
"GetRules",
|
||||
[{ id: id }]) +"&rnd=" + Math.floor(Math.random()*1001), {cache: false}),
|
||||
[{ id: id }])),
|
||||
'Failed to retreive stylesheets ');
|
||||
},
|
||||
|
||||
@@ -92,7 +92,7 @@ function stylesheetResource($q, $http, umbRequestHelper) {
|
||||
umbRequestHelper.getApiUrl(
|
||||
"stylesheetApiBaseUrl",
|
||||
"GetRulesByName",
|
||||
[{ name: name }]) +"&rnd=" + Math.floor(Math.random()*1001), {cache: false}),
|
||||
[{ name: name }])),
|
||||
'Failed to retreive stylesheets ');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Services.Description;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -15,6 +22,7 @@ namespace Umbraco.Web.Editors
|
||||
/// The API controller used for retrieving available stylesheets
|
||||
/// </summary>
|
||||
[PluginController("UmbracoApi")]
|
||||
[DisableBrowserCache]
|
||||
public class StylesheetController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
public IEnumerable<Stylesheet> GetAll()
|
||||
@@ -30,19 +38,19 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
public IEnumerable<StylesheetRule> GetRules(int id)
|
||||
{
|
||||
var css = new StyleSheet(id);
|
||||
var css = StyleSheet.GetStyleSheet(id, true, true);
|
||||
if (css == null)
|
||||
throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);
|
||||
return Enumerable.Empty<StylesheetRule>();
|
||||
|
||||
return css.Properties.Select(x => new StylesheetRule() { Id = x.Id, Name = x.Text, Selector = x.Alias });
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<StylesheetRule> GetRulesByName(string name)
|
||||
{
|
||||
var css = StyleSheet.GetByName(name);
|
||||
|
||||
if (css == null)
|
||||
throw new HttpResponseException(System.Net.HttpStatusCode.NotFound);
|
||||
return Enumerable.Empty<StylesheetRule>();
|
||||
|
||||
return css.Properties.Select(x => new StylesheetRule() { Id = x.Id, Name = x.Text, Selector = x.Alias });
|
||||
}
|
||||
|
||||
@@ -496,6 +496,7 @@
|
||||
<Compile Include="WebApi\Binders\MemberBinder.cs" />
|
||||
<Compile Include="WebApi\Filters\AngularAntiForgeryHelper.cs" />
|
||||
<Compile Include="WebApi\Filters\ClearAngularAntiForgeryTokenAttribute.cs" />
|
||||
<Compile Include="WebApi\Filters\DisableBrowserCacheAttribute.cs" />
|
||||
<Compile Include="WebApi\Filters\FilterGrouping.cs" />
|
||||
<Compile Include="WebApi\Filters\SetAngularAntiForgeryTokensAttribute.cs" />
|
||||
<Compile Include="WebApi\Filters\UmbracoBackOfficeLogoutAttribute.cs" />
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Web.WebApi.Filters
|
||||
{
|
||||
public class DisableBrowserCacheAttribute : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
|
||||
{
|
||||
//See: http://stackoverflow.com/questions/17755239/how-to-stop-chrome-from-caching-rest-response-from-webapi
|
||||
|
||||
base.OnActionExecuted(actionExecutedContext);
|
||||
|
||||
//TODO: This should all work without issue! BUT it doesn't, i have a feeling this might be fixed
|
||||
// in the next webapi version. ASP.Net is overwriting the cachecontrol all the time, some docs are here:
|
||||
// http://stackoverflow.com/questions/11547618/output-caching-for-an-apicontroller-mvc4-web-api
|
||||
// and I've checked the source code so doing this should cause it to write the headers we want but it doesnt.
|
||||
//So I've reverted to brute force on the HttpContext.
|
||||
//actionExecutedContext.Response.Headers.CacheControl = new CacheControlHeaderValue()
|
||||
//{
|
||||
// NoCache = true,
|
||||
// NoStore = true,
|
||||
// MaxAge = new TimeSpan(0),
|
||||
// MustRevalidate = true
|
||||
//};
|
||||
|
||||
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
||||
HttpContext.Current.Response.Cache.SetMaxAge(TimeSpan.Zero);
|
||||
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
|
||||
HttpContext.Current.Response.Cache.SetNoStore();
|
||||
|
||||
actionExecutedContext.Response.Headers.Pragma.Add(new NameValueHeaderValue("no-cache"));
|
||||
if (actionExecutedContext.Response.Content != null)
|
||||
{
|
||||
actionExecutedContext.Response.Content.Headers.Expires =
|
||||
//Mon, 01 Jan 1990 00:00:00 GMT
|
||||
new DateTimeOffset(1990, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user