I want to create custom cache for top menu
For this I have created cache.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Cache/etc/cache.xsd">
<type instance="Vendor\Module\Model\Cache\Vmenu" name="vmenu_cache_tag" translate="label,description">
<label>vmenu</label>
<description>My Menu</description>
</type>
</config>
Also created Model/Cache/Vmenu.php
<?php
namespace Vendor\Module\Model\Cache;
class Vmenu extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
{
const TYPE_IDENTIFIER = 'vmenu_cache_tag';
const CACHE_TAG = 'VMENU_CACHE_TAG';
/**
* @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool
*/
public function __construct(
\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool
) {
parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
}
}
Now my vmenu.phtml is calling from header.phtml
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Theme::html/vmenu.phtml")->toHtml(); ?>
My question is, how can I connect vmenu.phtml to my newly created cache?
asked May 14, 2019 at 7:10
Shoaib Munir
9,59210 gold badges54 silver badges109 bronze badges
1 Answer 1
you can also see this post https://www.optiweb.com/blog/magento-2-custom-cache-type/, I already create the module and I just need to associate the topmenu and the Cache save/loa function, thanks.
default