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.
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)
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?
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
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:
Hi Josip,
You can just do this :
And then your partial will be cached per page.
Dave
Unfortunately, I tried it but when I switch from English to German I still see the English version.
This should work. Maybe you should restart your website to make sure you have a empty cache.
Dave
Yeap I did it, updated clientDependency version, rebuild, new browser...but still same
Hmm.
Is the page the same content item for the different languages (but with different urls)
Or is it 2 seperate content items ?
Dave
Its same content item for different languages. I am using language variants so i have child node with name on English and on German
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 :
Dave
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
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
Hi Dave,
Thanks for clarifying things for me. I will investigate about donut caching :)
is working on a reply...