From 6eaf95a2d9624a8cfaf67895ee372f25a410ca26 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 27 Mar 2018 04:19:15 +0300 Subject: [PATCH] Themes: Implement doctrine cache #4 #5 --- flextype/Themes.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/flextype/Themes.php b/flextype/Themes.php index 5478ab8e..8a9d648f 100644 --- a/flextype/Themes.php +++ b/flextype/Themes.php @@ -34,12 +34,23 @@ class Themes // Theme Manifest $theme_manifest = []; + // Theme cache id + $theme_cache_id = ''; + // Get current theme $theme = Config::get('site.theme'); - if (Flextype::filesystem()->exists($theme_manifest_file = THEMES_PATH . '/' . $theme . '/' . $theme . '.yml')) { - $theme_manifest = Yaml::parseFile($theme_manifest_file); - Config::set('themes.'.Config::get('site.theme'), $theme_manifest); + // Create Unique Cache ID for Theme + $theme_cache_id = md5('theme' . THEMES_PATH . $theme); + + if (Cache::driver()->contains($theme_cache_id)) { + Config::set('themes.'.Config::get('site.theme'), Cache::driver()->fetch($theme_cache_id)); + } else { + if (Flextype::filesystem()->exists($theme_manifest_file = THEMES_PATH . '/' . $theme . '/' . $theme . '.yml')) { + $theme_manifest = Yaml::parseFile($theme_manifest_file); + Config::set('themes.'.Config::get('site.theme'), $theme_manifest); + Cache::driver()->save($theme_cache_id, $theme_manifest); + } } }