Skip to content

Commit

Permalink
fixed caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico Kaltofen committed Jun 29, 2018
1 parent 25abeeb commit a5e6735
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Manager/ListManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class ListManager implements ListManagerInterface
*/
protected $database;

/**
* @var array
*/
protected static $listConfigCache = [];

public function __construct(
ContaoFrameworkInterface $framework,
ListConfigRegistry $listConfigRegistry,
Expand Down Expand Up @@ -134,13 +139,15 @@ public function __construct(
*/
public function getListConfig(): ListConfigModel
{
$listConfigId = $this->moduleData['listConfig'];

// Caching
if (null !== $this->listConfig) {
if (isset(static::$listConfigCache[$listConfigId]) && null !== static::$listConfigCache[$listConfigId]) {
$this->listConfig = static::$listConfigCache[$listConfigId];

return $this->listConfig;
}

$listConfigId = $this->moduleData['listConfig'];

if (!$listConfigId || null === ($listConfig = $this->listConfigRegistry->findByPk($listConfigId))) {
throw new \Exception(sprintf('The module %s has no valid list config. Please set one.', $this->moduleData['id']));
}
Expand All @@ -150,6 +157,8 @@ public function getListConfig(): ListConfigModel

$this->listConfig = $listConfig;

static::$listConfigCache[$listConfigId] = $this->listConfig;

return $listConfig;
}

Expand Down

0 comments on commit a5e6735

Please sign in to comment.