I need to switch the currency based on user IP location so I'm using this auto currency extension, it works only when I disabled the FPC otherwise it just cache the previous content and never gets changed.
I'm looking to programmatically clear the varnish cache by the cache tag of the store currency. I tried the below logic in the observer (controller_action_predispatch) but it does not work.
protected $config;
protected $purgeCache;
public function __construct(
\Magento\PageCache\Model\Config $config,
\Magento\CacheInvalidate\Model\PurgeCache $purgeCache
) {
$this->config = $config;
$this->purgeCache = $purgeCache;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$tags = [];
$pattern = "((^|,)%s(,|$))";
$tags[] = sprintf($pattern, 'store');
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
}
Thanks in advance.