Skip to content

Commit 81ddee7

Browse files
committed
AC-8477: /page_cache/block/esi handles param enhancement
1 parent 7c7461a commit 81ddee7

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

app/code/Magento/PageCache/Controller/Block.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Framework\Validator\RegexFactory;
1212
use Magento\Framework\App\ObjectManager;
1313
use Magento\Framework\View\Layout\LayoutCacheKeyInterface;
14+
use Magento\PageCache\Model\Config;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
1416

1517
abstract class Block extends \Magento\Framework\App\Action\Action
1618
{
@@ -51,21 +53,28 @@ abstract class Block extends \Magento\Framework\App\Action\Action
5153
*/
5254
private const VALIDATION_RULE_PATTERN = '/^[a-z0-9]+[a-z0-9_]*$/i';
5355

56+
/**
57+
* @var ScopeConfigInterface
58+
*/
59+
private $config;
60+
5461
/**
5562
* @param \Magento\Framework\App\Action\Context $context
5663
* @param \Magento\Framework\Translate\InlineInterface $translateInline
5764
* @param Json $jsonSerializer
5865
* @param Base64Json $base64jsonSerializer
5966
* @param LayoutCacheKeyInterface $layoutCacheKey
6067
* @param RegexFactory|null $regexValidatorFactory
68+
* @param ScopeConfigInterface|null $config
6169
*/
6270
public function __construct(
6371
\Magento\Framework\App\Action\Context $context,
6472
\Magento\Framework\Translate\InlineInterface $translateInline,
6573
Json $jsonSerializer = null,
6674
Base64Json $base64jsonSerializer = null,
6775
LayoutCacheKeyInterface $layoutCacheKey = null,
68-
?RegexFactory $regexValidatorFactory = null
76+
?RegexFactory $regexValidatorFactory = null,
77+
ScopeConfigInterface $scopeConfig = null
6978
) {
7079
parent::__construct($context);
7180
$this->translateInline = $translateInline;
@@ -77,6 +86,7 @@ public function __construct(
7786
?: ObjectManager::getInstance()->get(LayoutCacheKeyInterface::class);
7887
$this->regexValidatorFactory = $regexValidatorFactory
7988
?: ObjectManager::getInstance()->get(RegexFactory::class);
89+
$this->config = $scopeConfig;
8090
}
8191

8292
/**
@@ -94,6 +104,10 @@ protected function _getBlocks()
94104
}
95105
$blocks = $this->jsonSerializer->unserialize($blocks);
96106
$handles = $this->base64jsonSerializer->unserialize($handles);
107+
108+
$handles_size = $this->config->getValue(Config::XML_HANDLES_SIZE);
109+
$handles = (count($handles) > $handles_size) ? array_splice($handles, 0, $handles_size) : $handles;
110+
97111
if (!$this->validateHandleParam($handles)) {
98112
return [];
99113
}

app/code/Magento/PageCache/Model/Config.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class Config
3434
*/
3535
public const XML_PAGECACHE_TTL = 'system/full_page_cache/ttl';
3636

37+
public const XML_HANDLES_SIZE = 'system/full_page_cache/handles_size';
38+
3739
public const XML_PAGECACHE_TYPE = 'system/full_page_cache/caching_application';
3840

3941
public const XML_VARNISH_PAGECACHE_ACCESS_LIST = 'system/full_page_cache/varnish/access_list';
@@ -125,6 +127,16 @@ public function getType()
125127
return (int)$this->_scopeConfig->getValue(self::XML_PAGECACHE_TYPE);
126128
}
127129

130+
/**
131+
* Return hnadles param size
132+
*
133+
* @return int
134+
*/
135+
public function getHandlesSize()
136+
{
137+
return (int)$this->_scopeConfig->getValue(self::XML_HANDLES_SIZE);
138+
}
139+
128140
/**
129141
* Return page lifetime
130142
*

app/code/Magento/PageCache/etc/adminhtml/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
<comment>Public content cache lifetime in seconds. If field is empty default value 86400 will be saved. </comment>
7979
<backend_model>Magento\PageCache\Model\System\Config\Backend\Ttl</backend_model>
8080
</field>
81+
<field id="handles_size" type="text" translate="label comment" sortOrder="5" showInDefault="1" canRestore="1">
82+
<label>Handles params size</label>
83+
<comment>Handles params size. For better performance use handles parameter size between 50 and 100, Max value 239. </comment>
84+
</field>
8185
</group>
8286
</section>
8387
</system>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<path>varnish4.vcl</path>
2525
</varnish4>
2626
<ttl>86400</ttl>
27+
<handles_size>100</handles_size>
2728
<caching_application>1</caching_application>
2829
<default>
2930
<access_list>localhost</access_list>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<type name="Magento\PageCache\Controller\Block">
3636
<arguments>
3737
<argument name="layoutCacheKey" xsi:type="object">Magento\Framework\View\Layout\LayoutCacheKeyInterface</argument>
38+
<argument name="scopeConfig" xsi:type="object">Magento\Framework\App\Config\ScopeConfigInterface\Proxy</argument>
3839
</arguments>
3940
</type>
4041
<type name="Magento\Framework\App\Cache\RuntimeStaleCacheStateModifier">

0 commit comments

Comments
 (0)