Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 9a1fadf

Browse files
authored
Merge pull request #8595 from ajithkumar-maragathavel/cache-type
Examples added for cache type
2 parents 42e11f8 + 6f0e158 commit 9a1fadf

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/guides/v2.3/extension-dev-guide/cache/partial-caching/create-cache-type.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The tag *scope* provides a mechanism for a cache type.
99

1010
## Cache type configuration {#m2devgde-cache-type-configuration}
1111

12-
Declare a new cache type in the `etc/cache.xml` file with the following attributes:
12+
Declare a new cache type in the `<module_dir>/etc/cache.xml` file with the following attributes:
1313

1414
| Attribute | Required? | Description |
1515
| --- | --- | --- |
@@ -162,3 +162,51 @@ $this->typeList->cleanType($cacheKey);
162162

163163
[tagscope]: {{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Cache/Frontend/Decorator/TagScope.php
164164
[type]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Customer/Model/Cache/Type/Notification.php
165+
166+
## Examples {#m2devgde-cache-type-model}
167+
168+
A cache type `translate` is declared in the Magento_Translation module using the `cache.xml` configuration file.
169+
170+
```xml
171+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Cache/etc/cache.xsd">
172+
<type name="translate" translate="label,description" instance="Magento\Framework\App\Cache\Type\Translate">
173+
<label>Translations</label>
174+
<description>Translation files</description>
175+
</type>
176+
</config>
177+
```
178+
179+
Translate cache type model class is defined in `Magento\Framework\App\Cache\Type\Translate.php` class. It must extend the `Magento\Framework\Cache\Frontend\Decorator\TagScope` class.
180+
181+
```php
182+
<?php
183+
/**
184+
* Copyright © Magento, Inc. All rights reserved.
185+
* See COPYING.txt for license details.
186+
*/
187+
namespace Magento\Framework\App\Cache\Type;
188+
189+
/**
190+
* System / Cache Management / Cache type "Translations"
191+
*/
192+
class Translate extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
193+
{
194+
/**
195+
* Cache type code unique among all cache types
196+
*/
197+
const TYPE_IDENTIFIER = 'translate';
198+
199+
/**
200+
* Cache tag used to distinguish the cache type from all other caches
201+
*/
202+
const CACHE_TAG = 'TRANSLATE';
203+
204+
/**
205+
* @param FrontendPool $cacheFrontendPool
206+
*/
207+
public function __construct(FrontendPool $cacheFrontendPool)
208+
{
209+
parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
210+
}
211+
}
212+
```

0 commit comments

Comments
 (0)