diff --git a/lang/en/cache.php b/lang/en/cache.php index b97ae2b189e..0c6b3692b25 100644 --- a/lang/en/cache.php +++ b/lang/en/cache.php @@ -59,6 +59,7 @@ $string['cachedef_navigation_expandcourse'] = 'Navigation expandable courses'; $string['cachedef_observers'] = 'Event observers'; $string['cachedef_plugin_functions'] = 'Plugins available callbacks'; $string['cachedef_plugin_manager'] = 'Plugin info manager'; +$string['cachedef_postprocessedcss'] = 'Post processed CSS'; $string['cachedef_tagindexbuilder'] = 'Search results for tagged items'; $string['cachedef_questiondata'] = 'Question definitions'; $string['cachedef_repositories'] = 'Repositories instances data'; diff --git a/lib/db/caches.php b/lib/db/caches.php index 9a8e9f24e5d..3c014a81f16 100644 --- a/lib/db/caches.php +++ b/lib/db/caches.php @@ -309,4 +309,12 @@ $definitions = array( 'simplevalues' => true, 'datasource' => '\core_message\time_last_message_between_users', ), + + // Caches processed CSS. + 'postprocessedcss' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true, + 'staticacceleration' => false, + ), ); diff --git a/lib/outputlib.php b/lib/outputlib.php index 09b30c57832..920b96fa2f0 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -60,6 +60,9 @@ function theme_reset_all_caches() { $cache->purge(); } + // Purge compiled post processed css. + cache::make('core', 'postprocessedcss')->purge(); + if ($PAGE) { $PAGE->reload_theme(); } @@ -901,6 +904,44 @@ class theme_config { return $csscontent; } + /** + * Set post processed CSS content cache. + * + * @param string $csscontent The post processed CSS content. + * @return bool True if the content was successfully cached. + */ + public function set_css_content_cache($csscontent) { + + $cache = cache::make('core', 'postprocessedcss'); + $key = $this->get_css_cache_key(); + + return $cache->set($key, $csscontent); + } + + /** + * Return cached post processed CSS content. + * + * @return bool|string The cached css content or false if not found. + */ + public function get_css_cached_content() { + + $key = $this->get_css_cache_key(); + $cache = cache::make('core', 'postprocessedcss'); + + return $cache->get($key); + } + + /** + * Generate the css content cache key. + * + * @return string The post processed css cache key. + */ + public function get_css_cache_key() { + $nosvg = (!$this->use_svg_icons()) ? 'nosvg_' : ''; + $rtlmode = ($this->rtlmode == true) ? 'rtl' : 'ltr'; + + return $nosvg . $this->name . '_' . $rtlmode; + } /** * Get the theme designer css markup, diff --git a/theme/styles.php b/theme/styles.php index 2fe8ec10876..9d7a39c6e9d 100644 --- a/theme/styles.php +++ b/theme/styles.php @@ -168,7 +168,10 @@ if ($type === 'editor') { } // Older IEs require smaller chunks. - $csscontent = $theme->get_css_content(); + if (!$csscontent = $theme->get_css_cached_content()) { + $csscontent = $theme->get_css_content(); + $theme->set_css_content_cache($csscontent); + } $relroot = preg_replace('|^http.?://[^/]+|', '', $CFG->wwwroot); if (!empty($slashargument)) { diff --git a/version.php b/version.php index 2ac0f1afee1..171ef5071de 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2016120503.07; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2016120503.08; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes.