Skip to content

Commit

Permalink
MDL-59142 core_theme: cache post-processed css
Browse files Browse the repository at this point in the history
Thanks Cameron Ball for the base patch
  • Loading branch information
lameze committed Jun 13, 2017
1 parent 4c6063b commit 4cc2f33
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions lang/en/cache.php
Expand Up @@ -60,6 +60,7 @@
$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';
Expand Down
7 changes: 7 additions & 0 deletions lib/db/caches.php
Expand Up @@ -328,4 +328,11 @@
'staticaccelerationsize' => 1
),

// Caches processed CSS.
'postprocessedcss' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'simpledata' => true,
'staticacceleration' => false,
),
);
41 changes: 41 additions & 0 deletions lib/outputlib.php
Expand Up @@ -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();
}
Expand Down Expand Up @@ -907,6 +910,44 @@ public function get_css_content() {

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,
Expand Down
5 changes: 4 additions & 1 deletion theme/styles.php
Expand Up @@ -168,7 +168,10 @@
}

// 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)) {
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2017060800.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017060800.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

Expand Down

0 comments on commit 4cc2f33

Please sign in to comment.