Merged v9/dev into this branch

This commit is contained in:
Zeegaan
2021-08-16 10:41:36 +02:00
156 changed files with 1351 additions and 1141 deletions

View File

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Web;
namespace Umbraco.Extensions
{
@@ -17,34 +18,40 @@ namespace Umbraco.Extensions
/// </summary>
/// <param name="appCaches"></param>
/// <param name="hostingEnvironment"></param>
/// <param name="umbracoContext"></param>
/// <param name="htmlHelper"></param>
/// <param name="partialViewName"></param>
/// <param name="model"></param>
/// <param name="cachedSeconds"></param>
/// <param name="cacheTimeout"></param>
/// <param name="cacheKey">used to cache the partial view, this key could change if it is cached by page or by member</param>
/// <param name="viewData"></param>
/// <returns></returns>
public static IHtmlContent CachedPartialView(
this AppCaches appCaches,
IHostingEnvironment hostingEnvironment,
IUmbracoContext umbracoContext,
IHtmlHelper htmlHelper,
string partialViewName,
object model,
int cachedSeconds,
TimeSpan cacheTimeout,
string cacheKey,
ViewDataDictionary viewData = null)
ViewDataDictionary viewData = null
)
{
//disable cached partials in debug mode: http://issues.umbraco.org/issue/U4-5940
if (hostingEnvironment.IsDebugMode)
//disable cached partials in preview mode: https://github.com/umbraco/Umbraco-CMS/issues/10384
if (hostingEnvironment.IsDebugMode || (umbracoContext?.InPreviewMode == true))
{
// just return a normal partial view instead
return htmlHelper.Partial(partialViewName, model, viewData);
}
return appCaches.RuntimeCache.GetCacheItem<IHtmlContent>(
var result = appCaches.RuntimeCache.GetCacheItem<IHtmlContent>(
CoreCacheHelperExtensions.PartialViewCacheKey + cacheKey,
() => htmlHelper.Partial(partialViewName, model, viewData),
timeout: new TimeSpan(0, 0, 0, cachedSeconds));
() => new HtmlString(htmlHelper.Partial(partialViewName, model, viewData).ToHtmlString()),
timeout: cacheTimeout);
return result;
}
}

View File

@@ -0,0 +1,17 @@
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Html;
namespace Umbraco.Extensions
{
public static class HtmlContentExtensions
{
public static string ToHtmlString(this IHtmlContent content)
{
using (var writer = new System.IO.StringWriter())
{
content.WriteTo(writer, HtmlEncoder.Default);
return writer.ToString();
}
}
}
}