I noticed that my macros set to cache by page do not change content if I switch language. Yet, it seems only to be the case with macros inserted via RTE.
Yes, I have run into this, it is I think an oversight with variants in Umbraco V8 - essentially the 'cache key' when 'caching is set for a macro' by page, uses the Id of the page along with the values of any macro parameters. In V7 this would ensure the cached version was different for each page, or if the macro was used on the same page with different parameters.
In V8 however, the language variant that uses the same macro 'will' have the same page id!! and so if the parameters are also the same in both versions of the macros on the different variant pages, you will get the issue you are experiencing, the output of the first requested macro cached upon the variant pages...
I've put a PR into the core of Umbraco to report/suggest a fix for this, to use the current language name as part of the cache key:
In the meantime, as a workaround - you could add a new parameter to your macro - called 'language' or similar... and ensure editors enter a different value here for each variant page - then the fact that the parameters have different values between the Macros will ensure that the cache is 'per' variant...
Macro caching per page and language
Hi
I noticed that my macros set to cache by page do not change content if I switch language. Yet, it seems only to be the case with macros inserted via RTE.
And I do not see any documentation for that situation on https://our.umbraco.com/documentation/Reference/Templating/Macros/#caching-macro-output
Anyone who has some experience to share on this?
Hi Kasper
Yes, I have run into this, it is I think an oversight with variants in Umbraco V8 - essentially the 'cache key' when 'caching is set for a macro' by page, uses the Id of the page along with the values of any macro parameters. In V7 this would ensure the cached version was different for each page, or if the macro was used on the same page with different parameters.
In V8 however, the language variant that uses the same macro 'will' have the same page id!! and so if the parameters are also the same in both versions of the macros on the different variant pages, you will get the issue you are experiencing, the output of the first requested macro cached upon the variant pages...
I've put a PR into the core of Umbraco to report/suggest a fix for this, to use the current language name as part of the cache key:
https://github.com/umbraco/Umbraco-CMS/pull/7555
In the meantime, as a workaround - you could add a new parameter to your macro - called 'language' or similar... and ensure editors enter a different value here for each variant page - then the fact that the parameters have different values between the Macros will ensure that the cache is 'per' variant...
regards
Marc
Hi Kasper
The PR above has been accepted and has been earmarked for release as part of Umbraco v8.7 ...
regards
Marc
is working on a reply...