2

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

1 Answer 1

2

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.

answered Dec 9, 2019 at 16:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.