Hi we have a Magento store. (2.3.6) ...

... and have the problem with the store switcher switching to wrong / outdated pages. We simply need the corresponding page in the other store/language to be the correct one.

I found out the following.

The is switcher works by writing a base64 encoding URL string (uenc) into the data-post attribute for each different language page via /magento/module-store/Block/Switcher.php->getTargetStorePostData(). enter image description here


When the page is regenerated, the store switcher takes the correct URL of the other-language page. However, once the cache is filled and the page comes out of the cache, the old opposite page (which was correct when the cache was filled) remains on all other pages. This is wrong/outdated when the page comes out of the cache. The function and template will also not be called again.


  • Cache emptied
  • call en_EN/page1 (uenc is correct)
  • store switch to en_EN/page1 redirects correctly
  • from en_EN/page1 switch to en_EN/page2
  • but here is now in the switchertemplate a string that leads to de_DE/page1 instead of page2 (testable on the conslole with php -a and echo base64_decode(strtr('uencstring', '-_,', '+/='));
  • the store change is executed accordingly to de_DE/page1

What I need is that the switcher block is not cached once for all pages but it should be cached seperately for each page. Does anyone have any idea how to set for individual blocks to be re-cached for each different url. Is the problem otherwise known I haven't found anything about it?

What I tried:

  • I tried to set the block in the theme to no-cache, which I think is a bad solution though. Since the whole page is then no longer cached.
  • $block->setCacheLifetime(0);in the block.

Info about our setup.

  • Magento 2.3.6 store (and that can't be changed).
  • varnish full page cache.
  • custom theme (magetigue/templatemonster theme/007)

1 Answer 1


I found a working solution.

I've reduced the parent block cache_lifetime to 1sec. (the least time a user needs potentially time to switch pages)

   <referenceBlock name="catalog.topnav">
            <argument name="cache_lifetime" xsi:type="number">1</argument>

Setting this to the block itself did not work. (Why?)

I don't know if this broke the full page cache. It seems to be as fast as before (after first cache generation) and the urls are good now.

Inspired by this article https://medium.com/@sivaschenko/5-block-types-from-caching-point-of-view-in-magento-2-cfdfc329d7dc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.