Cache

Custom Cache snippet

Use the Cache snippet in the Magento 2 module creator.

Files

Model/Cache/Module.php

<?php


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 instance="Mage2Gen\Module\Model\Cache\Module" name="module_cache_tag" translate="label,description">
		<label>Module</label>
		<description/>
	</type>
</config>