---
title: "How to Clear Cache For Specific CMS Page Programmatically in Magento 2?"
url: "https://magecomp.com/blog/clear-cache-for-specific-cms-page-programmatically-in-magento-2/"
date: "2020-05-11T18:00:43+00:00"
modified: "2025-02-20T10:03:09+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 380
reading_time: "2 min read"
summary: "Hello Magento Folks?,"
description: "Magento uses much memory when it is used and requires to flush the memory several times. How to Clear Cache For Specific CMS Page Programmatically in Magento 2"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "15 Best Magento 2 Extensions to Boost your Business in 2026"
    url: "https://magecomp.com/blog/best-magento-2-extensions-to-boost-your-business/"
  - title: "How to Add Comments to Order Programmatically After Place Order from Frontend in Magento 2?"
    url: "https://magecomp.com/blog/add-comments-to-order-programmatically-after-place-order-from-frontend-magento-2/"
  - title: "Magento 2: How to Add Group Product into Cart Individually"
    url: "https://magecomp.com/blog/magento-2-add-group-product-into-cart-individually/"
---

# How to Clear Cache For Specific CMS Page Programmatically in Magento 2?

_Published: May 11, 2020_  
_Author: Dhiren Vasoya_  

![How to Clear Cache For Specific CMS Page Programmatically in Magento 2](https://magecomp.com/blog/wp-content/uploads/2020/05/How-to-Clear-Cache-For-Specific-CMS-Page-Programmatically-in-Magento-2-1024x512.webp)

**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](https://magecomp.com/blog/how-to-change-default-active-tab-on-admin-order-view-page-magento-2/)**. So let’s begin?.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-3.webp)](https://magecomp.com/services/hyva-theme-development/)

## Introduction:
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.
## [![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

## Step to Flush Cache:
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 MagentoFrameworkAppInterface;

try {
    require __DIR__ . '/app/bootstrap.php';

} catch (Exception $e) {
    echo 'Autoload error: ' . $e->getMessage();
    exit(1);
}

try {
    $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $objectManager->get('MagentoFrameworkAppState')->setAreaCode('frontend');
    $fullPageCache = $objectManager->get(MagentoPageCacheModelCacheType::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.
## [![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-2.webp)](https://magecomp.com/magento-performance-optimization.html)

## Final Words:
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](https://magecomp.com/support/)** for more guidance. Till then Stay Home Stay Productive.
**Happy Coding.**

[![Quick Cache and Reindex](https://magecomp.com/blog/wp-content/uploads/2020/05/Quick-Cache-and-Reindex.png)](https://magecomp.com/magento-2-quick-cache-and-reindex.html?utm_source=blog&utm_medium=CTA&utm_campaign=cacheandreindex)


---

_View the original post at: [https://magecomp.com/blog/clear-cache-for-specific-cms-page-programmatically-in-magento-2/](https://magecomp.com/blog/clear-cache-for-specific-cms-page-programmatically-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-10-07 19:57:59 UTC_  
