Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

drupal_flush_all_caches() was previously not always able to properly (re-)initialize into a fully reset and fully working state, because module implementations of hook_flush_caches() had too many interdependencies on caches and data structures.

D7:

function mymodule_flush_caches() {
  // Reset my static variable (which is not a drupal_static).
  mymodule_info_reset();

  // Rebuild my stuff, depending on currently defined entity bundles.
  foreach (entity_get_info() as $entity_type => $info) {
    mymodule_rebuild_stuff($entity_type, $info['bundles']);
  }

  // Flush my cache_mymodule table.
  return array('mymodule');
}

D8:

function mymodule_cache_flush() {
  // Reset my static variable (which is not a drupal_static).
  // This reset function MUST NOT automatically rebuild its data after the reset.
  mymodule_info_reset();

  // Do NOT do anything else than resetting static variables or flushing caches!
  // All drupal_static()s are reset by drupal_flush_all_caches() already.
  return array('mymodule');
}

function mymodule_rebuild() {
  // Rebuild my stuff, depending on currently defined entity bundles.
  foreach (entity_get_info() as $entity_type => $info) {
    mymodule_rebuild_stuff($entity_type, $info['bundles']);
  }
}

Note: hook_flush_caches() was purposively renamed into hook_cache_flush() to ensure and force that all implementations are correctly updated. Do NOT perform any actions that may might build or rebuild data structures of other modules in hook_cache_flush().

Impacts: 
Module developers