Copied to clipboard

Flag this post as spam?

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


  • Josip 187 posts 652 karma points c-trib
    Apr 23, 2019 @ 11:59
    Josip
    0

    Clear cache on language switch

    I have multilingual website and i cache some of my partial views, how can i clear this cache when someone change the language of the website?

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Apr 25, 2019 @ 06:54
    Dave Woestenborghs
    0

    Hi Josip,

    I think it's better to cache your partial per language. If you clear cache when a visitor changes the language caching doesn't have much use. Especially when you have a very busy site.

    If you are pages have a different url per language caching the partial by page should be enough. Otherwise you can pass extra data (eg language) to the cached partial method.

    https://our.umbraco.com/documentation/Reference/Templating/Mvc/partial-views#caching

    Dave

  • Josip 187 posts 652 karma points c-trib
    Apr 25, 2019 @ 11:05
    Josip
    0

    Hi Dave ,

    I read the documentation but I do not understand it again if you can give me example i would be grateful. (My pages have diferent url for every language)

    This is my partial now:

    @Html.CachedPartial("Partials/HomePartials/_CategoriesSection", Model, 3600)
    
  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Apr 25, 2019 @ 11:26
    Dave Woestenborghs
    0

    Hi Josip,

    You can just do this :

    @Html.CachedPartial("Partials/HomePartials/_CategoriesSection", Model, 3600, true)
    

    And then your partial will be cached per page.

    Dave

  • Josip 187 posts 652 karma points c-trib
    Apr 25, 2019 @ 11:30
    Josip
    0

    Unfortunately, I tried it but when I switch from English to German I still see the English version.

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Apr 25, 2019 @ 11:47
    Dave Woestenborghs
    0

    This should work. Maybe you should restart your website to make sure you have a empty cache.

    Dave

  • Josip 187 posts 652 karma points c-trib
    Apr 25, 2019 @ 11:55
    Josip
    0

    Yeap I did it, updated clientDependency version, rebuild, new browser...but still same

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Apr 25, 2019 @ 11:56
    Dave Woestenborghs
    0

    Hmm.

    Is the page the same content item for the different languages (but with different urls)

    Or is it 2 seperate content items ?

    Dave

  • Josip 187 posts 652 karma points c-trib
    Apr 25, 2019 @ 12:04
    Josip
    0

    Its same content item for different languages. I am using language variants so i have child node with name on English and on German

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Apr 25, 2019 @ 13:42
    Dave Woestenborghs
    100

    Hi Josip,

    I never use the cached partial. But I maybe extending the call so you can build your own cache key does the trick :

    @Html.CachedPartial(""Partials/HomePartials/_CategoriesSection", Model, 3600, true, false, null , (model, viewData) =>  Model.GetCulture().Culture )
    

    Dave

  • Josip 187 posts 652 karma points c-trib
    Apr 25, 2019 @ 19:14
    Josip
    0

    Dave , thanks a lot, that worked.

    Can i ask why you never use cached partial?

    I use it for for listing my members under specific category.

    BR

    Josip

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Apr 26, 2019 @ 06:28
    Dave Woestenborghs
    0

    Hi Josip,

    I do all my rendering using Surface controllers. I use donut output caching to cache the response of my actions.

    So I do it a different level.

    Also the things that slow down rendering is quering your content, or in you case members. So I always try to optimize that.

    As a last resort I will cache the result of my query.

    So I try to avoid caching as much as possible. Because one of the hardest things in programming is cache invalidation.

    Dave

  • Josip 187 posts 652 karma points c-trib
    Apr 26, 2019 @ 11:42
    Josip
    0

    Hi Dave,

    Thanks for clarifying things for me. I will investigate about donut caching :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies