You are here

function mongodb_cache_flush_caches in MongoDB 7

Implements hook_flush_caches().

Support triggering expiration in modules not declaring their cache bins, either by taking them from an explicit variable, or by performing a discovery assuming the cache bin names to start by 'cache_'.

File

mongodb_cache/mongodb_cache_module.php, line 31
The MongoDB cache module.

Code

function mongodb_cache_flush_caches() {

  // Recursion protection, not static caching, so no drupal_static().
  static $reentry = FALSE;
  if ($reentry) {
    return [];
  }

  // Hardcoded in drupal_flush_all_caches() or system_cron(), but not declared
  // in system_flush_caches().
  $system_bins = [
    'cache',
    'cache_bootstrap',
    'cache_filter',
    'cache_form',
    'cache_menu',
    'cache_page',
    'cache_path',
  ];
  $reentry = TRUE;
  $owned_bins = module_invoke_all('flush_caches');
  $reentry = FALSE;
  $detected_bins = variable_get('mongodb_cache_extra_bins', NULL);

  // As with databases, NULL means unknown, so perform a discovery.
  if (!isset($detected_bins)) {
    $detected_bins = [];
    $names = mongodb()
      ->getCollectionNames();
    foreach ($names as $name) {
      if (strpos($name, 'cache_') === 0) {
        $detected_bins[] = $name;
      }
    }
  }
  $adopted_bins = array_diff($detected_bins, $system_bins, $owned_bins);
  return $adopted_bins;
}