Flush cache

It is really bad that youre mega menu extension requires flushing the entire magento cache to be able to see a change we make in the menu.  On a 10,000 product website that means we have to clear the cache for 10,000 products and 300 categories just to get your menu to show the latest content. I think that is very poor functionality.  Is there any way you can make a modification to it that allows us to clear the menu cache without flushing the entire cache?

4 answers

Profile photo of Mall Staff 184060.00 $tone January 16, 2020
Public

Hi there,

It is really bad that youre mega menu extension requires flushing the entire magento cache to be able to see a change we make in the menu

The custom cache process we applied in our module is to allow cache for the menu’s items data in non-cacheable pages (customer’s pages) of Magento. 

Is there any way you can make a modification to it that allows us to clear the menu cache without flushing the entire cache?

Yes, you can switch to use Magento’s block cache by the following steps:

+ Open the PHP file at: app/code/Ubertheme/UbMegaMenu/Block/Menu.php
and find the code lines:

protected function _generateMenuHtml($menuGroupId)
{
$html = null;
$cacheId = $this->getCustomCacheId();
$html = $this->cache->load($cacheId);
if (!$html) {
//get menu items and build menu markup html
$items = $this->_dataHelper->getMenuItems($menuGroupId, $this->_configs);
if ($items) {
//build menu items data
$this->_megaHelper->rebuildData($items);
//generate menu
$html = $this->_megaHelper->genMenu();
} else {
$html = '<span class="no-menu">' . __('There are not menu items found.') . '</span>';
}
//save to cache
$this->cache->save($this->getSerializer()->serialize($html), $cacheId, [], $this->_configs['cache_lifetime']);
} else {
$html = $this->getSerializer()->unserialize($html);
}

return $html;
}

and replace it with:

protected function _generateMenuHtml($menuGroupId)
{
//get menu items
$items = $this->_dataHelper->getMenuItems($menuGroupId, $this->_configs);
if ($items) {
//build menu items data
$this->_megaHelper->rebuildData($items);
//generate menu
$output = $this->_megaHelper->genMenu();
} else {
$output = '<span class="no-menu">' . __('There are not menu items found.') . '</span>';
}

return $output;
}

+ Once done, open the XML file at: app/code/Ubertheme/UbMegaMenu/view/frontend/layout/default.xml
and find the code line:

<!--<argument name="cache_lifetime" xsi:type="string">86400</argument>-->

and replace it with:

<argument name="cache_lifetime" xsi:type="string">86400</argument>

And then, run these CLI commands:
php -f bin/magento setup:upgrade;
php -f bin/magento cache:clean;

Please note such changes will disable the cache of menu items in non-cacheable pages: Customer’s pages. This is the default working rule of Magento for block cache or full-page cache.
 
Regards,
Mall.
 

#1
Profile photo of weismannweb 100.00 $tone January 20, 2020
Public

Why is it we have to reduce the caching capability to support this?  Why don’t you add your own cache type or make a way to clear the cache even if cache of menu items in non-cacheable pages: Customer’s pages.  Also, can you tell me what pages are customer pages?
 
Does this mean caching after adding to cart?
Does this mean caching after a customer logs in?

#2
Profile photo of Mall Staff 184060.00 $tone January 21, 2020
Public

Hi there,

Why is it we have to reduce the caching capability to support this?

As mentioned in my previous reply, the custom cache process we provided is to enable cached menu items data for both non-cacheable pages: Customer’s pages: register, login, remind password pages…

Why don’t you add your own cache type or make a way to clear the cache even if cache of menu items in non-cacheable pages

We will consider the custom cache type you mentioned in the coming time.

Also, can you tell me what pages are customer pages?

These are non-cacheable pages that I mentioned: register, login, remind password, checkout pages…
 
To enable the Magento’s block cache in our module, please follow additional step as follows:
 
+ Open the PHP file at: app/code/Ubertheme/UbMegaMenu/Block/Menu.php
and find the code lines:

protected function getCacheLifetime()
{
return null;
}

and replace it with:

/* protected function getCacheLifetime()
{
return null;
} */

Hope that helps. 
 
PS. Our team is about to have a 7-Days Festival Event starting from Jan 23, we’re sorry for certain delay in response if you reach out to us during this period. We do have a technical team in charge, however it will take us longer to follow up your questions. Thanks for your understanding.
 
Regards,
Mall.
 

#3
Profile photo of Mall Staff 184060.00 $tone January 21, 2020
Public

Hi there,

Why don’t you add your own cache type or make a way to clear the cache even if cache of menu items in non-cacheable pages

I have added a Magento custom cache type in our develop branch of our UB MegaMenu module.
For a quick workaround, you can follow these steps to quickly apply this new tweak code at your end:

+ Step 1: Download the XML file at here
and upload to the file path: app/code/Ubertheme/UbMegaMenu/etc/cache.xml
+ Step 2: Download the PHP file at here
and upload to the file path: app/code/Ubertheme/UbMegaMenu/Model/Cache/Type.php
(you need to create this folder path: app/code/Ubertheme/UbMegaMenu/Model/Cache)
+ Step 3: Download the PHP file at here
and upload to the file path: app/code/Ubertheme/UbMegaMenu/Helper/Cache.php
+ Step 4: Download the PHP file at here
and upload to overwrite the file at: app/code/Ubertheme/UbMegaMenu/Block/Menu.php
+ Step 5: Once done, you can run the following CLI commands to apply the new changes:
php -f bin/magento setup:upgrade;
php -f bin/magento cache:enable ubmegamenu;
 
Hope that helps. 
 
PS. Once the changes are applied, you can now manage our UB Mega Menu cache using this CLI: php -f bin/magento cache:clean ubmegamenu

Regards,
Mall.
 
 
 

#4

Please login or Register to Submit Answer

Written By

Comments