---
title: "How to clean cache by tag id in Magento 2"
url: "https://dolphinwebsolution.com/how-to-clean-cache-by-tag-id-in-magento-2"
date: "2022-05-31T14:33:02+05:30"
modified: "2023-08-24T09:17:55+05:30"
author:
  name: "Chirag Parmar"
categories:
  - "Magento"
tags:
  - "cache"
  - "clean cache"
  - "MAGENTO2"
  - "tags"
word_count: 259
reading_time: "2 min read"
summary: "Magento 2 provide good cache mechanism for faster serving pages to browser. Sometimes we require to clean cache by tag id as per custom requirement. In recent projects there was custom requirement ..."
description: "Magento 2 provide good cache mechanism for faster serving pages to browser. Sometimes we require to clean cache by tag id as per custom requirement. In recen..."
keywords: "clean cache by tag id,magento2, cache, clean cache, MAGENTO2, tags"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to add Custom Information in Invoice PDF in Magento2?"
    url: "https://dolphinwebsolution.com/how-to-add-custom-information-in-invoice-pdf-in-magento2"
  - title: "Magento 2 SMTP for Gmail not working"
    url: "https://dolphinwebsolution.com/magento-2-smtp-for-gmail-not-working"
---

# How to clean cache by tag id in Magento 2

_Published: May 31, 2022_  
_Author: Chirag Parmar_  

![](https://dolphinwebsolution.com/wp-content/uploads/2023/02/Frame-55-1-1024x536.jpg)

Magento 2 provide good cache mechanism for faster serving pages to browser. Sometimes we require to clean cache by tag id as per custom requirement. In recent projects there was custom requirement in which customer want to clear cache for particular cms page only after save it. So i did it in detail and found better solution for clear cache for cms page , catalog product , catalog category and even you can clear cache for custom module also.

#### How to Find / Identfy tag of frontend section for clean cache by tag id ?

In this article i will explain how you can identify tag for clear cache for particular area of magento site. Cache id is used to identify a specific cache record. If you save something in the cache you can later retrieve it by its id. First of all you need to find proper **CACHE\_ID** and **CACHE\_TAG**. You can find it easily by opening particular model.

For example if you open “vendor/magento/module-catalog/Model/Product.php” then you will see kind of below code :

![Best AI Agent Development Companies in India (2026)](https://dolphinwebsolution.com/wp-content/uploads/2021/10/Screen-Shot-2021-10-29-at-3-300x189.png)
These tags are used for clear cache by tags.

```
So now let see how can we clean caches partially with tags,

private $fullPageCache;

private function getCache()
{
    if (!$this->fullPageCache) {
        $this->fullPageCache = \Magento\Framework\App\ObjectManager::getInstance()->get(
            \Magento\PageCache\Model\Cache\Type::class
        );
    }
    return $this->fullPageCache;
}

public function cleanByTags()
{
    $productId = 21; //Id of the Product whose Cache need to be cleaned
    $tags = ['CAT_P_'.$productId];
    $this->getCache()->clean(\Zend_Cache::CLEANING_MODE_MATCHING_TAG, $tags);
}
```


---

_View the original post at: [https://dolphinwebsolution.com/how-to-clean-cache-by-tag-id-in-magento-2](https://dolphinwebsolution.com/how-to-clean-cache-by-tag-id-in-magento-2)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-26 06:14:31 UTC_  
