Replace caching of Theme config with generic YAML caching (#4526)

Credit to @Samuell1. Fixes issues related to complexity of the existing approach / cache invalidation by just using the caching built in to YAML::parseFile().
This commit is contained in:
Samuell 2019-09-25 19:36:35 +02:00 committed by Luke Towers
parent 744263eb4b
commit 33d149fe1a
2 changed files with 2 additions and 18 deletions

View File

@ -50,7 +50,6 @@ class Theme
const ACTIVE_KEY = 'cms::theme.active';
const EDIT_KEY = 'cms::theme.edit';
const CONFIG_KEY = 'cms::theme.config';
/**
* Loads the theme.
@ -341,21 +340,7 @@ class Theme
return $this->configCache = [];
}
try {
if (Config::get('app.debug', false)) {
$config = Yaml::parseFile($path);
} else {
$cacheKey = self::CONFIG_KEY.'::'.$this->getDirName();
$config = Cache::rememberForever($cacheKey, function () use ($path) {
return Yaml::parseFile($path);
});
}
}
catch (Exception $ex) {
// Cache failed
$config = Yaml::parseFile($path);
}
$config = Yaml::parseFile($path);
/**
* @event cms.theme.extendConfig
@ -505,7 +490,6 @@ class Theme
Cache::forget(self::ACTIVE_KEY);
Cache::forget(self::EDIT_KEY);
Cache::forget(self::CONFIG_KEY.'::'.(new self)->getDirName());
}
/**

View File

@ -65,7 +65,7 @@ trait ConfigMaker
));
}
$config = Yaml::parse(File::get($configFile));
$config = Yaml::parseFile($configFile);
/*
* Extensibility