Skip to content

Commit 1960b3f

Browse files
committed
AC-13719: Cache Keys associated with FPC on Magento 2.4.7 multi-store implementations
Enabled the plugin Magento\PageCache\Model\App\CacheIdentifierPlugin responsible for adding MAGE_RUN_TYPE and MAGE_RUN_CODE prefix to the cache key
1 parent 4ca7360 commit 1960b3f

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
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" type="Magento\PageCache\Model\App\CacheIdentifierPlugin" sortOrder="10"/>
11+
</type>
912
<type name="Magento\Framework\App\PageCache\Cache">
1013
<plugin name="fpc-type-plugin" type="Magento\PageCache\Model\App\PageCachePlugin"/>
1114
</type>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All rights reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageCache\Model\App;
9+
10+
use Magento\Framework\App\PageCache\Identifier;
11+
use Magento\Framework\App\Request\Http;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\PageCache\Model\Cache\Type;
14+
use Magento\Store\Model\StoreManager;
15+
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
16+
use Magento\Store\Test\Fixture\Store as StoreFixture;
17+
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
18+
use Magento\TestFramework\Fixture\Config as ConfigFixture;
19+
use Magento\TestFramework\Fixture\DataFixture;
20+
use Magento\TestFramework\Fixture\DataFixtureStorage;
21+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
22+
use Magento\TestFramework\Fixture\DbIsolation;
23+
use Magento\TestFramework\Helper\Bootstrap;
24+
use PHPUnit\Framework\TestCase;
25+
26+
/**
27+
* Integration test for \Magento\PageCache\Model\App\CacheIdentifierPlugin
28+
*/
29+
class CacheIdentifierPluginTest extends TestCase
30+
{
31+
/**
32+
* @var ObjectManagerInterface
33+
*/
34+
private $objectManager;
35+
36+
/**
37+
* @var Http
38+
*/
39+
private $request;
40+
41+
/**
42+
* @var Identifier
43+
*/
44+
private $identifier;
45+
46+
/**
47+
* @var DataFixtureStorage
48+
*/
49+
private $fixtures;
50+
51+
protected function setUp(): void
52+
{
53+
$this->objectManager = Bootstrap::getObjectManager();
54+
$this->request = $this->objectManager->get(Http::class);
55+
$this->identifier = $this->objectManager->get(Identifier::class);
56+
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
57+
58+
// Enable the cache type
59+
$this->objectManager->get(\Magento\Framework\App\Cache\StateInterface::class)
60+
->setEnabled(Type::TYPE_IDENTIFIER, true);
61+
}
62+
63+
/**
64+
* Test that cache identifier includes run type and run code
65+
*/
66+
#[
67+
DbIsolation(false),
68+
ConfigFixture('system/full_page_cache/caching_application', '1', 'store'),
69+
ConfigFixture('system/full_page_cache/enabled', '1', 'store'),
70+
DataFixture(WebsiteFixture::class, as: 'website'),
71+
DataFixture(StoreGroupFixture::class, ['website_id' => '$website.id$'], 'store_group'),
72+
DataFixture(StoreFixture::class, ['store_group_id' => '$store_group.id$'], 'store')
73+
]
74+
public function testAfterGetValueWithRunTypeAndCode()
75+
{
76+
$storeCode = $this->fixtures->get('store')->getCode();
77+
$serverParams = [
78+
StoreManager::PARAM_RUN_TYPE => 'store',
79+
StoreManager::PARAM_RUN_CODE => $storeCode
80+
];
81+
$this->request->setServer(new \Laminas\Stdlib\Parameters($serverParams));
82+
83+
$result = $this->identifier->getValue();
84+
$this->assertNotEmpty($result);
85+
$this->assertStringContainsString('MAGE_RUN_TYPE=store', $result);
86+
$this->assertStringContainsString('MAGE_RUN_CODE=' . $storeCode, $result);
87+
}
88+
}

0 commit comments

Comments
 (0)