Skip to content

Commit 1fd33a8

Browse files
digitalrisedorsetglo63652
authored andcommitted
Moved identifier page cache model outside of library folder to allow to work with non library models for the cache logic
1 parent 837125c commit 1fd33a8

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Magento\PageCache\Model\App\Request\Http;
5+
6+
use Magento\Framework\App\ObjectManager;
7+
use Magento\Framework\App\PageCache\IdentifierInterface;
8+
use Magento\Framework\Serialize\Serializer\Json;
9+
10+
class Identifier implements IdentifierInterface
11+
{
12+
/**
13+
* @var \Magento\Framework\App\Request\Http
14+
*/
15+
protected $request;
16+
17+
/**
18+
* @var \Magento\Framework\App\Http\Context
19+
*/
20+
protected $context;
21+
22+
/**
23+
* @var Json
24+
*/
25+
private $serializer;
26+
27+
/**
28+
* @param \Magento\Framework\App\Request\Http $request
29+
* @param \Magento\Framework\App\Http\Context $context
30+
* @param Json|null $serializer
31+
*/
32+
public function __construct(
33+
\Magento\Framework\App\Request\Http $request,
34+
\Magento\Framework\App\Http\Context $context,
35+
Json $serializer = null,
36+
private IdentifierStoreReader $identifierStoreReader
37+
) {
38+
$this->request = $request;
39+
$this->context = $context;
40+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
41+
}
42+
43+
/**
44+
* Return unique page identifier
45+
*
46+
* @return string
47+
*/
48+
public function getValue()
49+
{
50+
$data = [
51+
$this->request->isSecure(),
52+
$this->request->getUriString(),
53+
$this->request->get(\Magento\Framework\App\Response\Http::COOKIE_VARY_STRING)
54+
?: $this->context->getVaryString()
55+
];
56+
57+
$data = $this->identifierStoreReader->getPageTagsWithStoreCacheTags($data);
58+
59+
return sha1($this->serializer->serialize($data));
60+
}
61+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@
4444
<preference for="Magento\PageCache\Model\VclGeneratorInterface" type="Magento\PageCache\Model\Varnish\VclGenerator"/>
4545
<preference for="Magento\PageCache\Model\VclTemplateLocatorInterface" type="Magento\PageCache\Model\Varnish\VclTemplateLocator"/>
4646
<preference for="Magento\PageCache\Model\Spi\PageCacheTagsPreprocessorInterface" type="Magento\PageCache\Model\PageCacheTagsPreprocessorComposite"/>
47+
48+
<preference for="Magento\Framework\App\PageCache\IdentifierInterface" type="Magento\PageCache\Model\App\Request\Http\Identifier"/>
4749
</config>

lib/internal/Magento/Framework/App/PageCache/Identifier.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use Magento\Framework\App\ObjectManager;
99
use Magento\Framework\Serialize\Serializer\Json;
10-
use Magento\PageCache\Model\App\Request\Http\IdentifierStoreReader;
1110

1211
/**
1312
* Page unique identifier
@@ -37,8 +36,7 @@ class Identifier implements IdentifierInterface
3736
public function __construct(
3837
\Magento\Framework\App\Request\Http $request,
3938
\Magento\Framework\App\Http\Context $context,
40-
Json $serializer = null,
41-
private IdentifierStoreReader $identifierStoreReader
39+
Json $serializer = null
4240
) {
4341
$this->request = $request;
4442
$this->context = $context;
@@ -59,8 +57,6 @@ public function getValue()
5957
?: $this->context->getVaryString()
6058
];
6159

62-
$data = $this->identifierStoreReader->getPageTagsWithStoreCacheTags($data);
63-
6460
return sha1($this->serializer->serialize($data));
6561
}
6662
}

0 commit comments

Comments
 (0)