Skip to content

Commit bba9f0d

Browse files
author
David Verholen
committed
save vary data to db
1 parent 6812777 commit bba9f0d

File tree

4 files changed

+70
-13
lines changed

4 files changed

+70
-13
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* SaveVaryData
5+
*
6+
* @copyright Copyright © 2019 brandung GmbH & Co. KG. All rights reserved.
7+
* @author david.verholen@brandung.de
8+
*/
9+
10+
namespace Firegento\CacheWarmup\Plugin\CacheIdentifier;
11+
12+
use Firegento\CacheWarmup\Api\CacheVaryDataRepositoryInterface;
13+
use Magento\Framework\App\Http\Context;
14+
15+
class SaveVaryData
16+
{
17+
/**
18+
* @var Context
19+
*/
20+
private $httpContext;
21+
/**
22+
* @var CacheVaryDataRepositoryInterface
23+
*/
24+
private $varyDataRepository;
25+
26+
public function __construct(Context $httpContext, CacheVaryDataRepositoryInterface $varyDataRepository)
27+
{
28+
$this->httpContext = $httpContext;
29+
$this->varyDataRepository = $varyDataRepository;
30+
}
31+
32+
/**
33+
* Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual
34+
*
35+
* @param \Magento\Framework\App\PageCache\Identifier $identifier
36+
* @param string $result
37+
* @return string
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
39+
*/
40+
public function afterGetValue(\Magento\Framework\App\PageCache\Identifier $identifier, $result): string
41+
{
42+
$varyData = $this->httpContext->toArray()['data'];
43+
$this->varyDataRepository->save($varyData);
44+
return $result;
45+
}
46+
}

Setup/InstallSchema.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@ private function getCacheTagTableDefinition(SchemaSetupInterface $setup): \Magen
6161
private function getVaryDataTableDefinition(SchemaSetupInterface $setup): \Magento\Framework\DB\Ddl\Table
6262
{
6363
return $setup->getConnection()->newTable($setup->getTable('cache_vary_data'))
64-
->addColumn(
65-
'id',
66-
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
67-
null,
68-
[
69-
'identity' => true,
70-
'nullable' => false,
71-
'primary' => true,
72-
'unsigned' => true,
73-
],
74-
'Cache Vary Data ID'
75-
)
7664
->addColumn(
7765
'vary_data',
7866
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
7967
255,
80-
['nullable' => false],
68+
[
69+
'nullable' => false,
70+
'primary' => true
71+
],
8172
'Cache Vary Data'
8273
)
74+
->addIndex(
75+
$setup->getIdxName(
76+
'cache_vary_data',
77+
['vary_data'],
78+
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
79+
),
80+
['vary_data'],
81+
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
82+
)
8383
->setComment('Cache Vary Data Table');
8484
}
8585

etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@
3333
type="Firegento\CacheWarmup\Model\Tag\CacheTag"
3434
/>
3535

36+
<preference
37+
for="Firegento\CacheWarmup\Api\CacheVaryDataRepositoryInterface"
38+
type="Firegento\CacheWarmup\Model\CacheVaryDataRepository"
39+
/>
40+
3641
</config>

etc/frontend/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3+
<type name="Magento\Framework\App\PageCache\Identifier">
4+
<plugin name="saveVaryData" type="\Firegento\CacheWarmup\Plugin\CacheIdentifier\SaveVaryData"/>
5+
</type>
6+
</config>

0 commit comments

Comments
 (0)