You are here

function _js_cache_initialize in JS Callback Handler 7.2

Initializes the cache system and our custom handler.

1 call to _js_cache_initialize()
js_execute_request in ./js.module
Loads the requested module and executes the requested callback.

File

./js.module, line 736
JavaScript callback handler module.

Code

function _js_cache_initialize() {
  global $conf;

  // Skip autoloading, we do not need its overhead. Additionally it may trigger
  // cache initialization.
  module_load_include('php', 'js', 'src/JsProxyCache');

  // Collect all the explicitly configured cache bins.
  $default_key = JsProxyCache::DEFAULT_BIN_KEY;
  $cache_bin_keys = array_values(array_filter(array_keys($conf), function ($key) {
    return strpos($key, 'cache_class_') === 0;
  }));
  $cache_bin_keys[] = $default_key;

  // Save the current configuration and override it to make sure an instance of
  // our custom wrapper is instantiated for each configured bin.
  $cache_conf = array();
  $default_class = isset($conf[$default_key]) ? $conf[$default_key] : 'DrupalDatabaseCache';
  foreach ($cache_bin_keys as $bin_key) {
    $cache_conf[$bin_key] = isset($conf[$bin_key]) ? $conf[$bin_key] : $default_class;
    $conf[$bin_key] = 'JsProxyCache';
  }

  // Finally ensure our custom wrappers know which actual cache backend they are
  // supposed to use.
  JsProxyCache::setConf($cache_conf);

  // Configure excluded cache classes.
  $excluded_conf = !empty($conf['js_excluded_cache_classes']) ? $conf['js_excluded_cache_classes'] : array(
    'DrupalFakeCache',
  );
  JsProxyCache::setExcludedConf($excluded_conf);

  // Memcache requires an additional bootstrap phase to access variables.
  if (!empty($cache_conf[$default_key]) && $cache_conf[$default_key] === 'MemCacheDrupal') {
    js_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
  }
}