Magento - Clear cache on a single category

Magento - Clear cache on a single category

August 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - Clear cache on a single category

Clearing Magento Cache on a Single Category

Magento’s Full Page Cache (FPC) is powerful, but sometimes it can cause issues like showing out-of-stock products as in-stock after they’ve been sold out. If you’ve enabled FPC and set “Show Out of Stock Products” to “No,” but the category page still displays an out-of-stock product that should be hidden, clearing the cache on that specific category is crucial.

Understanding Magento’s Cache Tags

Before we dive into clearing the cache for a single category, let’s understand how Magento handles caching. Each cacheable object in Magento has a unique cache tag associated with it. These tags are used to identify which cached data needs to be invalidated when a particular object changes.

For categories, the default cache tag is catalog_category. However, using this tag as-is won’t clear the cache for a specific category; it will clear the cache for all categories.

Clearing Cache for a Specific Category

To clear the cache for only one category, you need to use a more specific identifier. Magento allows you to create a unique key for each cached object by combining the cache type with an identification code of the object being cached.

Here’s how you can do it:

Mage::app()->cleanCache('catalog_category'.$category_id);

Replace category_id with the actual ID of the category you want to clear. For example, if your category ID is 123:

$categoryId = 123;
Mage::app()->cleanCache('catalog_category'.$categoryId);

This code cleans the cache for a single category by using a unique key that includes the cache type (catalog_category) and the specific category’s ID. This approach ensures that only the cache associated with the targeted category is invalidated.

When to Use This Method

You should use this method when you’ve made changes to a specific category, such as:

  • Updating the category name or description
  • Changing its visibility or status
  • Adding or removing products from it
  • Modifying any attribute that affects how the category is displayed

By clearing only the cache for the affected category, you can improve the performance of your store by minimizing unnecessary cache invalidations.

Conclusion

Clearing Magento’s cache on a single category requires understanding how Magento uses cache tags and creating a unique key for each cached object. By using the catalog_category cache type combined with the specific category ID, you can effectively clear only the cache associated with that particular category.

Remember to use this method judiciously; clearing the cache too frequently can negatively impact your store’s performance. Only clear the cache when necessary and after making significant changes to a specific category.

For more advanced caching strategies in Magento, I recommend checking out Laravel Company’s comprehensive guide on Magento Performance Optimization.

Catalog Cache Errors

Our network