diff --git a/drush/views.drush.inc b/drush/views.drush.inc index dd83cd837f17330fb9af1bddb64800abf26e7739..87d2eff385d1ca640cb7ee71e389e6bf75d8f3d8 100644 --- a/drush/views.drush.inc +++ b/drush/views.drush.inc @@ -490,8 +490,7 @@ function _views_drush_changestatus($viewnames = array(), $status = NULL) { variable_set('views_defaults', $views_status); views_invalidate_cache(); drush_log(dt("Views cache was cleared"), 'ok'); - menu_router_rebuild(); - drush_log(dt("Menu cache was cleared"), 'ok'); + drush_log(dt("Menu cache is set to be rebuilt on the next request."), 'ok'); } } } diff --git a/includes/admin.inc b/includes/admin.inc index 925250ba836b2cacbac636bd5f79983da71bf2c8..8a902690b4426a2e35d570eb637163420e6e82a1 100644 --- a/includes/admin.inc +++ b/includes/admin.inc @@ -722,9 +722,7 @@ function views_ui_add_form_save_submit($form, &$form_state) { $form_state['redirect'] = 'admin/structure/views'; } $view->save(); - menu_router_rebuild(); - cache('cache_views')->flush(); - cache_invalidate(array('content' => TRUE)); + $form_state['redirect'] = 'admin/structure/views'; if (!empty($view->display['page'])) { $display = $view->display['page']; @@ -2173,15 +2171,6 @@ function views_ui_edit_view_form_submit($form, &$form_state) { $form_state['view']->save(); drupal_set_message(t('The view %name has been saved.', array('%name' => $form_state['view']->get_human_name()))); - // Make sure menu items get rebuilt as neces - menu_router_rebuild(); - - // Clear the views cache. - cache('cache_views')->flush(); - - // Clear the page cache. - cache_invalidate(array('content' => TRUE)); - // Remove this view from cache so we can edit it properly. ctools_object_cache_clear('view', $form_state['view']->name); } diff --git a/lib/Drupal/views/View.php b/lib/Drupal/views/View.php index 40c46761536b686aea7c84f4e9b9df456c1f4673..6d09b8d74d15871ac5b23085df3731e6355b3e25 100644 --- a/lib/Drupal/views/View.php +++ b/lib/Drupal/views/View.php @@ -1862,9 +1862,8 @@ function save() { $this->save_locale_strings(); - cache('cache_views')->delete('views_urls'); - // Clear the page cache as well. - cache_invalidate(array('content' => TRUE)); + // Clear caches. + views_invalidate_cache(); } /** @@ -1901,10 +1900,8 @@ function delete($clear = TRUE) { cache('cache_views')->delete('views_query:' . $this->name); if ($clear) { - // Clear the block and page caches. - cache_invalidate(array('content' => TRUE)); - // Force a menu rebuild when a view is deleted. - menu_router_rebuild(); + // Clear caches. + views_invalidate_cache(); } } diff --git a/views.api.php b/views.api.php index 567b8ebcf82beb5603ebc656eb3819479d45f5fd..72ed887566cf1fb6d575997c4c322e7882bfe0b7 100644 --- a/views.api.php +++ b/views.api.php @@ -603,7 +603,7 @@ function hook_views_plugins() { 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', ), ); - + return array( 'module' => 'views', // This just tells our themes are elsewhere. 'argument validator' => array( @@ -1081,6 +1081,18 @@ function hook_views_ajax_data_alter(&$commands, $view) { } } +/** + * Allow modules to respond to the Views cache being invalidated. + * + * This hook should fire whenever a view is enabled, disabled, created, + * updated, or deleted. + * + * @see views_invalidate_cache() + */ +function hook_views_invalidate_cache() { + cache('mymodule')->deletePrefix('views:*'); +} + /** * @} */ diff --git a/views.module b/views.module index 52fde865d31392da37c006e9422f23e6e2e72272..3edee251d340806cba1f1c47e67e19f60b69e537 100644 --- a/views.module +++ b/views.module @@ -951,7 +951,17 @@ function views_field_delete_instance($instance) { * Invalidate the views cache, forcing a rebuild on the next grab of table data. */ function views_invalidate_cache() { + // Clear the views cache. cache('cache_views')->flush(); + + // Clear the page and block cache. + cache_invalidate(array('content' => TRUE)); + + // Set the menu as needed to be rebuilt. + variable_set('menu_rebuild_needed', TRUE); + + // Allow modules to respond to the Views cache being cleared. + module_invoke_all('views_invalidate_cache'); } /** @@ -1675,8 +1685,6 @@ function views_export_view(&$view, $indent = '') { function views_export_status($view, $status) { ctools_export_set_object_status($view, $status); views_invalidate_cache(); - // Set the menu to be rebuilt. - variable_set('menu_rebuild_needed', TRUE); } // ------------------------------------------------------------------