Drupal - How can I invalidate a cache on a specific View?

If you know the name of the view that you want to clear, then you can clear the caches specific to that view by calling a function like the following:

/**
 * Function to invalidate selected views caches to enable the action forms to work
 */
function mymodule_invalidate_views_cache($view_name) {
  cache_clear_all('ctools_export:views_view:' . $view_name, 'cache_views', TRUE);
  cache_clear_all($view_name, 'cache_views_data', TRUE);
}

I needed this to allow VBO actions with configuration forms to be able to work while views caching was enabled (I am using content caching). I called this twice, once in the function mymodule_myaction_form() and again in the function mymodule_myaction_submit().


I believe the function you are looking for is cache_flush from the views cache plugin.