Back to learning

Cache tags are metadata that get associated with a cached object which enables very targeted flushing of content. The tags are generally returned in a custom HTTP Header, which a CDN is configured to read, so the information can be stored alongside the page/resource.

Modern CMS's, eg Magento 2, Drupal 8/9, Typo3, are adopting cache tags to provide built in support for Full Page Caching. For example, Magento 2 will list any products and categories that are on a page in the cache tags. eg:

X-Magento-Tags: cms_b_footer-links,store,cms_b,cms_b_top-contact,cms_b_footer-introduce,cms_b_top_header,cat_c_43,cat_c_p_43,cat_p_59828,cat_p,cat_p_60050,cat_p_59461,cat_p_59470,cat_p_59639,cat_p_59629,cat_p_59649,cat_p_11610,cat_p_55938,cat_p_3529,cat_p_7920,cat_p_43007,cat_p_43035,cat_p_55330,cat_p_43028,cat_p_13734,cat_p_43101,cat_p_43102,cat_p_55334

Then, if a category is updated in the Magento admin, eg category ID 43, Magento issues a flush request to the cache with the tag

cat_c_43

The CDN can then look up all pages that have that tag and invalidate them. Without cache tags it would be up to Magento to determine which urls category 43 appeared on, and then issue a flush request for every URL. This would be a very database intensive effort and result in unnecessary flushes, as not every page would be in the cache.

Cache tags are an elegant way of providing targeted cache invalidation.

© PEAKHOUR.IO PTY LTD 2024   ABN 76 619 930 826    All rights reserved.