You are here

function advagg_get_render_cache in Advanced CSS/JS Aggregation 7.2

Given the full css and js scope array return back the render cache.

Parameters

array $full_css: Array from advagg_get_css() with #attached removed because it was built by _advagg_build_css_arrays_for_rendering().

array $js_scope_array: Array built from iterations of advagg_get_js() inside of _advagg_build_js_arrays_for_rendering().

Return value

array Array containing the $css_cache, $js_cache, $css_cache_id, $js_cache_id.

1 call to advagg_get_render_cache()
_advagg_process_html in ./advagg.module
Replacement for template_process_html().

File

./advagg.module, line 1893
Advanced CSS/JS aggregation module.

Code

function advagg_get_render_cache(array $full_css, array $js_scope_array) {
  $cids = array();
  $css_cache_id = '';
  $js_cache_id = '';

  // Get advagg hash.
  $hooks_hash = advagg_get_current_hooks_hash();
  $serialize_function = variable_get('advagg_serialize', ADVAGG_SERIALIZE);
  if (advagg_file_aggregation_enabled('css')) {

    // Generate css cache id.
    $cids[] = $css_cache_id = 'advagg:css:full:1.1:' . $hooks_hash . ':' . drupal_hash_base64($serialize_function($full_css));
  }
  if (advagg_file_aggregation_enabled('js')) {

    // Generate js cache id.
    $cids[] = $js_cache_id = 'advagg:js:full:1.1:' . $hooks_hash . ':' . drupal_hash_base64($serialize_function($js_scope_array));
  }
  if (!empty($cids)) {

    // Get the cached data.
    $cached_data = cache_get_multiple($cids, 'cache_advagg_aggregates');

    // Set variables from the cache.
    if (isset($cached_data[$css_cache_id])) {
      $css_cache = $cached_data[$css_cache_id];
    }
    if (isset($cached_data[$js_cache_id])) {
      $js_cache = $cached_data[$js_cache_id];
    }
  }

  // Special handling if the css is loaded via JS.
  if (!empty($css_cache) && empty($js_cache) && advagg_css_in_js($css_cache)) {

    // If CSS is being loaded via JavaScript and the css cache is set but the
    // js cache is not set; then unset the css cache as well.
    unset($css_cache);
  }

  // Set to empty arrays on a cache miss.
  if (!isset($css_cache)) {
    $css_cache = new stdClass();
  }
  if (!isset($js_cache)) {
    $js_cache = new stdClass();
  }
  return array(
    $css_cache,
    $js_cache,
    $css_cache_id,
    $js_cache_id,
  );
}