Hello Magento Folks?,
How are you all working? I hope all are safe and productive at home. Today I am with another interesting solution for How to Clear Cache For Specific CMS Page Programmatically in Magento 2. Meanwhile, If you have not visited the lately published article then have a look at MAGENTO 2: How to Change Default Active Tab on Admin Order View Page. So let’s begin?.
Basically, Magento uses much memory when it works and requires to flush the memory several times in a day. Many times Magento Developer requires flush cache for specific cms page because of the changes on cms pages or call another phtml file from cms page or a change in this phtml file. So directly after that you need to flush cache and for that flushing, the whole site cache is not appropriate because it will result in the downtime of the site. Therefore, make a practice to flush only specific cms pages and flush not affect the whole site.
For that, we have to create a PHP script which you need to put on the root in your installed Magento folder and you can directly run on a web browser.
<?php use Magento\Framework\AppInterface; try { require __DIR__ . '/app/bootstrap.php'; } catch (\Exception $e) { echo 'Autoload error: ' . $e->getMessage(); exit(1); } try { $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $objectManager->get('Magento\Framework\App\State')->setAreaCode('frontend'); $fullPageCache = $objectManager->get(\Magento\PageCache\Model\Cache\Type::class); $fullPageCache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array('cms_p_2')); // Here 2 is a cms page id here you can pass any cms page id } catch(\Exception $e){ echo "Error :"; echo $e->getMessage(); }
Hence, by applying the above you will be capable of flushing the specific CMS page successfully.
I hope the above solution to flush the specific CMS page was helpful for you. If you like the article then don’t forget to share with your Magento Friends and also comment down your reviews in the comment section below regarding the above solution. If you find any difficulties then do contact our Support Team for more guidance. Till then Stay Home Stay Productive.
Happy Coding.
Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…
E-commerce has transformed the way consumers shop for products and services and interact with businesses.…
The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…
Hello Magento Friends, In today’s blog, we will discuss adding a header and footer to…
Hello React Native Friends, Building a visually appealing and responsive mobile app is crucial in…
We have brought exciting news for Magento store owners. Hyvä Themes recently released 1.3.6 and…
View Comments
hi Dhiren;
thanks for posting this post .
I was wondering how can I modify the code to clear cache only for a specific page like the landing page