Skip to content

Commit 9ba84f3

Browse files
digitalrisedorsetglo63652
authored andcommitted
Added a new page cache identifier model to unify the page cache identifier with store configuration
1 parent fcc6f0a commit 9ba84f3

File tree

4 files changed

+84
-7
lines changed

4 files changed

+84
-7
lines changed

app/code/Magento/PageCache/Model/App/Request/Http/IdentifierForSave.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class IdentifierForSave implements IdentifierInterface
2323
* @param Json $serializer
2424
*/
2525
public function __construct(
26-
private Http $request,
27-
private Context $context,
28-
private Json $serializer
26+
private Http $request,
27+
private Context $context,
28+
private Json $serializer,
29+
private IdentifierStoreReader $identifierStoreReader,
2930
) {
3031
}
3132

@@ -42,6 +43,8 @@ public function getValue()
4243
$this->context->getVaryString()
4344
];
4445

46+
$data = $this->identifierStoreReader->getPageTagsWithStoreCacheTags($data);
47+
4548
return sha1($this->serializer->serialize($data));
4649
}
4750
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Magento\PageCache\Model\App\Request\Http;
5+
6+
use Magento\Store\Model\StoreManager;
7+
8+
class IdentifierStoreReader
9+
{
10+
/**
11+
* @var \Magento\Framework\View\DesignExceptions
12+
*/
13+
private $designExceptions;
14+
15+
/**
16+
* @var \Magento\Framework\App\RequestInterface
17+
*/
18+
private $request;
19+
20+
/**
21+
* @var \Magento\PageCache\Model\Config
22+
*/
23+
private $config;
24+
25+
/**
26+
* @param \Magento\Framework\View\DesignExceptions $designExceptions
27+
* @param \Magento\Framework\App\RequestInterface $request
28+
* @param \Magento\PageCache\Model\Config $config
29+
*/
30+
public function __construct(
31+
\Magento\Framework\View\DesignExceptions $designExceptions,
32+
\Magento\Framework\App\RequestInterface $request,
33+
\Magento\PageCache\Model\Config $config
34+
) {
35+
$this->designExceptions = $designExceptions;
36+
$this->request = $request;
37+
$this->config = $config;
38+
}
39+
40+
/**
41+
* Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual
42+
*
43+
* @param \Magento\Framework\App\PageCache\Identifier $identifier
44+
* @param string $result
45+
* @return array
46+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
47+
*/
48+
public function getPageTagsWithStoreCacheTags($data): ?array
49+
{
50+
if ($this->config->getType() === \Magento\PageCache\Model\Config::BUILT_IN && $this->config->isEnabled()) {
51+
$ruleDesignException = $this->designExceptions->getThemeByRequest($this->request);
52+
if ($ruleDesignException !== false) {
53+
$data['DESIGN'] = $ruleDesignException;
54+
}
55+
56+
if ($runType = $this->request->getServerValue(StoreManager::PARAM_RUN_TYPE)) {
57+
$data[StoreManager::PARAM_RUN_TYPE] = $runType;
58+
}
59+
60+
if ($runCode = $this->request->getServerValue(StoreManager::PARAM_RUN_CODE)) {
61+
$data[StoreManager::PARAM_RUN_CODE] = $runCode;
62+
}
63+
}
64+
65+
return $data;
66+
}
67+
}

app/code/Magento/PageCache/etc/di.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9-
<type name="Magento\Framework\App\PageCache\Identifier">
10-
<plugin name="core-app-area-design-exception-plugin"
11-
type="Magento\PageCache\Model\App\CacheIdentifierPlugin" sortOrder="10"/>
12-
</type>
139
<type name="Magento\Framework\App\PageCache\Cache">
1410
<plugin name="fpc-type-plugin" type="Magento\PageCache\Model\App\PageCachePlugin"/>
1511
</type>

app/code/Magento/PageCache/etc/frontend/di.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,15 @@
3131
<argument name="identifierForSave" xsi:type="object">Magento\PageCache\Model\App\Request\Http\IdentifierForSave</argument>
3232
</arguments>
3333
</type>
34+
35+
<type name="Magento\PageCache\Model\App\Request\Http\IdentifierForSave">
36+
<arguments>
37+
<argument name="identifierStoreReader" xsi:type="object">Magento\PageCache\Model\App\Request\Http\IdentifierStoreReader</argument>
38+
</arguments>
39+
</type>
40+
<type name="Magento\Framework\App\PageCache\Identifier">
41+
<arguments>
42+
<argument name="identifierStoreReader" xsi:type="object">Magento\PageCache\Model\App\Request\Http\IdentifierStoreReader</argument>
43+
</arguments>
44+
</type>
3445
</config>

0 commit comments

Comments
 (0)