Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Zoki 27 posts 103 karma points
    Apr 12, 2019 @ 09:51
    Zoki
    0

    CachedPartial with V8

    I might be missing something, but CachedPartial isn't playing well with multiple languages in Umbraco V8. Is there any additional key I need to set up if I:

    a) don't want cachedpartial to be cached by page

    b) I want it to be cached by language

    This doesn't work (it displays wrong language):

    @Html.CachedPartial("FooPartial", Model, 14400)

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 12, 2019 @ 10:28
    Corné Strijkert
    100

    Hi Zoki,

    Maybe you can try this. When you have a look at the implementation of the CachedPartial() method on https://github.com/umbraco/Umbraco-CMS/blob/853087a75044b814df458457dc9a1f778cc89749/src/Umbraco.Web/HtmlHelperRenderExtensions.cs you will see this part of code:

    if (contextualKeyBuilder != null)
    {
        var contextualKey = contextualKeyBuilder(model, viewData);
        cacheKey.AppendFormat("c{0}-", contextualKey);
    }
    

    It seems the multilanguage behavior is not supported by default when you have a look at the implementation of CachedPartial(), so you can try to implement your own contextualKeyBuilder:

    @Html.CachedPartial("FooPartial", Model, 14400, false, false, null, (o, dictionary) => System.Threading.Thread.CurrentThread.CurrentCulture.Name)
    

    I'm curious if this will work, please let me know.

  • Zoki 27 posts 103 karma points
    Apr 12, 2019 @ 11:14
    Zoki
    1

    It appears to be working well Corne :)

    I could really have tried that myself and not bother you, I was only expecting that CachedPartial method was extended for new language system.

    But I'm ok with this solution too.

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft