This commit is contained in:
Martijn de Boer 2024-03-22 18:55:39 +01:00
parent 9eae0a8eee
commit 153d3fe0b8
2 changed files with 19 additions and 1 deletions

View file

@ -1,7 +1,20 @@
<?php <?php
class Cache { class Cache {
protected static $templateCache = [];
protected static $resourceCache = []; protected static $resourceCache = [];
public static function getTemplateFromCache(string $name) {
if (isset(self::$templateCache[$name])) {
return self::$templateCache[$name];
}
return null;
}
public static function setTemplateToCache(string $name, $data) {
self::$templateCache[$name] = $data;
}
protected static function fillResourceCache() { protected static function fillResourceCache() {
$db = new Database(); $db = new Database();
$sql = "SELECT * FROM `resources`"; $sql = "SELECT * FROM `resources`";

View file

@ -20,7 +20,12 @@ class Template {
$class = is_object($options) && isset($options->class) ? new $options->class($this, $options) : new EmptyTemplate($this, $options); $class = is_object($options) && isset($options->class) ? new $options->class($this, $options) : new EmptyTemplate($this, $options);
$class->load(); $class->load();
$contents = Cache::getTemplateFromCache($this->template);
if (is_null($contents)) {
$contents = file_get_contents(TEMPLATE_DIR . "/" . $this->template); $contents = file_get_contents(TEMPLATE_DIR . "/" . $this->template);
Cache::setTemplateToCache($this->template, $contents);
}
$class->pretransform(); $class->pretransform();
// Replace includes of templates // Replace includes of templates