0

I have created cache.xml inside app/code/Custom/CacheType/etc/cache.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Cache/etc/cache.xsd">
    <type name="ansar" translate="label,description" instance="Custom\CacheType\Model\Cache\Type">
        <label>Custom Type Cache</label>
        <description>Custom types cache</description>
    </type>
</config>

And i have created Model file in location Custom/CacheType/Model/Cache/Type.php

<?php

namespace Custom\CacheType\Model\Cache;

class Type extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
{
    const TYPE_IDENTIFIER = 'ansar';

    const CACHE_TAG = 'ANSAR';

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

Buts its not displaying in admin section cache management.

enter image description here

0

1 Answer 1

2

I am seeing no issue in your code, it could be happening because you have used generalized keywords like type etc. Try this code, it should work.

app/code/Custom/CacheType/etc/cache.xml

Code would be this:

<?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="Custom\CacheType\Model\Cache\Ansar" name="ansar_cache_tag" translate="label,description">
        <label>ansar</label>
        <description>Custom types cache</description>
    </type>
</config>

and for model file: app/code/Custom/CacheType/Model/Cache/Ansar

<?php
namespace Custom\CacheType\Model\Cache;

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

    const TYPE_IDENTIFIER = 'ansar_cache_tag';
    const CACHE_TAG = 'ANSAR_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);
    }
}

Please try this code, hope this will work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.