Cache the theme config (#4270)

Fixes #4265. Credit to @Samuell1
This commit is contained in:
Samuell 2019-04-19 18:59:27 +02:00 committed by Luke Towers
parent 044ae054f8
commit a69455d409

View File

@ -48,6 +48,7 @@ class Theme
const ACTIVE_KEY = 'cms::theme.active';
const EDIT_KEY = 'cms::theme.edit';
const CONFIG_KEY = 'cms::theme.config';
/**
* Loads the theme.
@ -336,7 +337,16 @@ class Theme
return $this->configCache = [];
}
$config = Yaml::parseFile($path);
try {
$config = Cache::rememberForever(self::CONFIG_KEY, function() use ($path) {
return Yaml::parseFile($path);
});
}
catch (Exception $ex) {
// Cache failed
$config = Yaml::parseFile($path);
}
/**
* @event cms.theme.extendConfig
@ -455,6 +465,8 @@ class Theme
$contents = Yaml::render($values);
File::put($path, $contents);
$this->configCache = $values;
self::resetCache();
}
/**
@ -484,6 +496,7 @@ class Theme
Cache::forget(self::ACTIVE_KEY);
Cache::forget(self::EDIT_KEY);
Cache::forget(self::CONFIG_KEY);
}
/**