How to invalidate Full Page Catch type in Magento 2?

You can invalidate the full_page catch in Magento 2 using invalidate() method from the TypeListInterface.

In some cases you need to invalidate the catch after some event or trigger on the code, you need to do it via passing cache type code as a string or pass multiple catch type list using an array.

Let’s we have to invalidate the full_page cache programmatically, First see the base definition of the method,

    /**
     *
     * @param string|array $typeCode
     * @return void
     */
    public function invalidate($typeCode);

Now Code to Invalidate full-page catch in Model class,

<?php
namespace Jesadiya\InvalidateCache\Model;

use Magento\Framework\App\Cache\TypeListInterface;

class InvalidateCache
{
	/**
     * Cache type code
     */
    const FULL_PAGE_TYPE_IDENTIFIER = 'full_page';

    /**
     * @var TypeListInterface
     */
    protected $cacheTypeList;

    public function __construct(
        TypeListInterface $cacheTypeList
    ) {
        $this->cacheTypeList = $cacheTypeList;
    }

    /**
     * Invalidate the cache
     *
     * @param string
     * @return void
     */
    public function fullpageCacheInValidate($cache_id): void
    {
        $this->cacheTypeList->invalidate(self::FULL_PAGE_TYPE_IDENTIFIER);
    }
}

Using the given code snippet, you can invalidate the cache type in Magento 2.

You can invalidate multiple catch types at one request by passing an array as a catch type list.

This is the code snippet to do catch invalidate the process.