Skip to content
Code-Schnipsel Gruppen Projekte
Commit 64e12fff erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

refactor: pcsg/kunden/bow-modellhandel-template#24 - brick cache

Übergeordneter cfb886f5
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -60,6 +60,11 @@ class Brick extends QUI\QDOM
*/
protected $cssClasses = [];
/**
* @var string
*/
protected $hash;
/**
* Constructor
*
......@@ -172,6 +177,8 @@ public function __construct($params = [])
$this->customfields = $customfields;
}
}
$this->hash = $this->createBrickHash();
}
/**
......@@ -230,6 +237,31 @@ public function check()
return $this;
}
/**
* Create a unique brick hash
* which is created from the brick data
*
* @return string
*/
protected function createBrickHash()
{
$attributes = $this->getAttributes();
$hashParams = [];
foreach ($attributes as $name => $value) {
if (\is_object($value)) {
continue;
}
$hashParams[$name] = \serialize($value);
}
$hash = \serialize($hashParams);
$hash = \md5($hash);
return $hash;
}
/**
* Return the HTML of the Brick
*
......@@ -239,6 +271,16 @@ public function check()
*/
public function create()
{
$cacheName = Manager::getBrickCacheNamespace()
.\md5($this->getType())
.'/'
.$this->hash;
try {
return QUI\Cache\Manager::get($cacheName);
} catch (QUI\Exception $Exception) {
}
if ($this->getAttribute('type') == 'content') {
$_classes = [
'brick-'.$this->id
......@@ -292,7 +334,10 @@ public function create()
'classesStr' => $classesStr
]);
return $Engine->fetch(\dirname(__FILE__).'/Brick.html');
$result = $Engine->fetch(\dirname(__FILE__).'/Brick.html');
QUI\Cache\Manager::set($cacheName, $result);
return $result;
}
$Control = $this->getControl();
......@@ -324,7 +369,10 @@ public function create()
$Control->addCSSClass($cssClass);
}
return $Control->create();
$result = $Control->create();
QUI\Cache\Manager::set($cacheName, $result);
return $result;
}
/**
......
......@@ -99,6 +99,16 @@ public static function getUIDTable()
return QUI::getDBTableName(self::TABLE_UID);
}
/**
* Return the long time cache namespace
*
* @return string
*/
public static function getBrickCacheNamespace()
{
return 'quiqqer/package/quiqqer/bricks/';
}
/**
* Creates a new brick for the project
*
......@@ -1025,6 +1035,10 @@ public function saveBrick($brickId, array $brickData)
);
QUI\Cache\Manager::clear($cache);
QUI\Cache\Manager::clear(
self::getBrickCacheNamespace().\md5($type)
);
}
/**
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren