Invalidate the views cache, forcing a rebuild on the next grab of table data.
function views_invalidate_cache() {
// Clear the views cache.
cache('views_info')
->deleteAll();
// Clear the page and block cache.
Cache::deleteTags(array(
'content' => TRUE,
));
// Set the menu as needed to be rebuilt.
Drupal::state()
->set('menu_rebuild_needed', TRUE);
$module_handler = Drupal::moduleHandler();
// Set the router to be rebuild.
// @todo Figure out why the cache rebuild is trigged but the route table
// does not exist yet.
if (db_table_exists('router')) {
Drupal::service('router.builder')
->rebuild();
}
// Invalidate the block cache to update views block derivatives.
if ($module_handler
->moduleExists('block')) {
Drupal::service('plugin.manager.block')
->clearCachedDefinitions();
}
// Allow modules to respond to the Views cache being cleared.
$module_handler
->invokeAll('views_invalidate_cache');
}