Skip to content

Commit

Permalink
Fixed issue with CachedPartial that cached an unmaterialized value, t…
Browse files Browse the repository at this point in the history
…hat could not be used on cache hits.
  • Loading branch information
bergmania committed Aug 11, 2021
1 parent c2d54f5 commit 442310d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
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

0 comments on commit 442310d

Please sign in to comment.