-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TE-8140 moved cache key generation to the separate class
- Loading branch information
Showing
5 changed files
with
110 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...kerShop/Yves/ShopApplication/Twig/Widget/CacheKeyGenerator/CacheKeyGeneratorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerShop\Yves\ShopApplication\Twig\Widget\CacheKeyGenerator; | ||
|
||
interface CacheKeyGeneratorInterface | ||
{ | ||
/** | ||
* @param string $widgetClassName | ||
* @param array $arguments | ||
* | ||
* @return string|null | ||
*/ | ||
public function generateCacheKey(string $widgetClassName, array $arguments): ?string; | ||
} |
63 changes: 63 additions & 0 deletions
63
...ykerShop/Yves/ShopApplication/Twig/Widget/CacheKeyGenerator/StrategyCacheKeyGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerShop\Yves\ShopApplication\Twig\Widget\CacheKeyGenerator; | ||
|
||
class StrategyCacheKeyGenerator implements CacheKeyGeneratorInterface | ||
{ | ||
/** | ||
* @var \SprykerShop\Yves\ShopApplicationExtension\Dependency\Plugin\WidgetCacheKeyGeneratorStrategyPluginInterface[] | ||
*/ | ||
protected static $widgetCacheKeyGeneratorPlugins = []; | ||
|
||
/** | ||
* @param \SprykerShop\Yves\ShopApplicationExtension\Dependency\Plugin\WidgetCacheKeyGeneratorStrategyPluginInterface[] $widgetCacheKeyGeneratorPlugins | ||
*/ | ||
public function __construct(array $widgetCacheKeyGeneratorPlugins = []) | ||
{ | ||
if (!static::$widgetCacheKeyGeneratorPlugins) { | ||
static::$widgetCacheKeyGeneratorPlugins = $this->indexWidgetCacheKeyGeneratorPlugins($widgetCacheKeyGeneratorPlugins); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $widgetClassName | ||
* @param array $arguments | ||
* | ||
* @return string|null | ||
*/ | ||
public function generateCacheKey(string $widgetClassName, array $arguments): ?string | ||
{ | ||
if (isset(static::$widgetCacheKeyGeneratorPlugins[$widgetClassName])) { | ||
$key = static::$widgetCacheKeyGeneratorPlugins[$widgetClassName]->generateCacheKey($arguments); | ||
|
||
if ($key === null) { | ||
return null; | ||
} | ||
|
||
return md5($widgetClassName . $key); | ||
} | ||
|
||
return md5($widgetClassName . serialize($arguments)); | ||
} | ||
|
||
/** | ||
* @param \SprykerShop\Yves\ShopApplicationExtension\Dependency\Plugin\WidgetCacheKeyGeneratorStrategyPluginInterface[] $widgetCacheKeyGeneratorPlugins | ||
* | ||
* @return \SprykerShop\Yves\ShopApplicationExtension\Dependency\Plugin\WidgetCacheKeyGeneratorStrategyPluginInterface[] | ||
*/ | ||
protected function indexWidgetCacheKeyGeneratorPlugins(array $widgetCacheKeyGeneratorPlugins): array | ||
{ | ||
$indexedWidgetCacheKeyGeneratorPlugins = []; | ||
|
||
foreach ($widgetCacheKeyGeneratorPlugins as $widgetCacheKeyGeneratorPlugin) { | ||
$indexedWidgetCacheKeyGeneratorPlugins[$widgetCacheKeyGeneratorPlugin->getWidgetClassName()] = $widgetCacheKeyGeneratorPlugin; | ||
} | ||
|
||
return $indexedWidgetCacheKeyGeneratorPlugins; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters