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">
        <description>My Menu</description>

Also created Model/Cache/Vmenu.php

namespace Vendor\Module\Model\Cache;
class Vmenu extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
    const TYPE_IDENTIFIER = '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?


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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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