Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with CachedPartial that cached an unmaterialized value #10832

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Umbraco.Web.Common/Extensions/CacheHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class CacheHelperExtensions
/// <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>
Expand All @@ -30,7 +30,7 @@ public static IHtmlContent CachedPartialView(
IHtmlHelper htmlHelper,
string partialViewName,
object model,
int cachedSeconds,
TimeSpan cacheTimeout,
string cacheKey,
ViewDataDictionary viewData = null)
{
Expand All @@ -41,10 +41,12 @@ public static IHtmlContent CachedPartialView(
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;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static async Task<IHtmlContent> CachedPartialAsync(
this IHtmlHelper htmlHelper,
string partialViewName,
object model,
int cachedSeconds,
TimeSpan cacheTimeout,
bool cacheByPage = false,
bool cacheByMember = false,
ViewDataDictionary viewData = null,
Expand Down Expand Up @@ -129,7 +129,7 @@ public static async Task<IHtmlContent> CachedPartialAsync(
var appCaches = GetRequiredService<AppCaches>(htmlHelper);
var hostingEnvironment = GetRequiredService<IHostingEnvironment>(htmlHelper);

return appCaches.CachedPartialView(hostingEnvironment, htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData);
return appCaches.CachedPartialView(hostingEnvironment, htmlHelper, partialViewName, model, cacheTimeout, cacheKey.ToString(), viewData);
}

// public static IHtmlContent EditorFor<T>(this IHtmlHelper htmlHelper, string templateName = "", string htmlFieldName = "", object additionalViewData = null)
Expand Down