Cache

Custom Cache snippet

Use the snippet in the Magento 2 module creator.

Files

Model/Cache/Module.php

<?php
declare(strict_types=1);

namespace Mage2Gen\Module\Model\Cache;

class Module extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
{

    const TYPE_IDENTIFIER = 'module_cache_tag';
    const CACHE_TAG = 'MODULE_CACHE_TAG';

    /**
     * @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool
     */
    public function __construct(
        \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool
    ) {
        parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
    }
}

etc/cache.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Cache/etc/cache.xsd">
	<type name="module_cache_tag" translate="label,description" instance="Mage2Gen\Module\Model\Cache\Module">
		<label>Module</label>
		<description/>
	</type>
</config>