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

Commit 5bf5ec9

Browse files
Examples added for cache type
1 parent 9b53c46 commit 5bf5ec9

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
| --- | --- | --- |
@@ -83,3 +83,51 @@ You must specify the following parameters:
8383

8484
[tagscope]: {{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Cache/Frontend/Decorator/TagScope.php
8585
[type]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Customer/Model/Cache/Type/Notification.php
86+
87+
## Examples {#m2devgde-cache-type-model}
88+
89+
A cache type `translate` is declared in the Magento_Translation module using the `cache.xml` configuration file.
90+
91+
```xml
92+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Cache/etc/cache.xsd">
93+
<type name="translate" translate="label,description" instance="Magento\Framework\App\Cache\Type\Translate">
94+
<label>Translations</label>
95+
<description>Translation files</description>
96+
</type>
97+
</config>
98+
```
99+
100+
Translate cache type model class is defined in `Magento\Framework\App\Cache\Type\Translate.php` class. It must extends `Magento\Framework\Cache\Frontend\Decorator\TagScope` class.
101+
102+
```php
103+
<?php
104+
/**
105+
* Copyright © Magento, Inc. All rights reserved.
106+
* See COPYING.txt for license details.
107+
*/
108+
namespace Magento\Framework\App\Cache\Type;
109+
110+
/**
111+
* System / Cache Management / Cache type "Translations"
112+
*/
113+
class Translate extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
114+
{
115+
/**
116+
* Cache type code unique among all cache types
117+
*/
118+
const TYPE_IDENTIFIER = 'translate';
119+
120+
/**
121+
* Cache tag used to distinguish the cache type from all other cache
122+
*/
123+
const CACHE_TAG = 'TRANSLATE';
124+
125+
/**
126+
* @param FrontendPool $cacheFrontendPool
127+
*/
128+
public function __construct(FrontendPool $cacheFrontendPool)
129+
{
130+
parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
131+
}
132+
}
133+
```

0 commit comments

Comments
 (0)