You are here

function cache_actions_action_clear_views_cache in Cache Actions 6

Same name and namespace in other branches
  1. 6.2 cache_actions.rules.inc \cache_actions_action_clear_views_cache()
  2. 7.2 cache_actions.rules.inc \cache_actions_action_clear_views_cache()
  3. 7 cache_actions.rules.inc \cache_actions_action_clear_views_cache()

This action clears the cache of a specific view.

Parameters

string $view the name of the view.:

File

./cache_actions.rules.inc, line 229
This file provides the rules integration for this module. @author Fabian Sörqvist <fabian.sorqvist@gmail.com>

Code

function cache_actions_action_clear_views_cache($view) {

  // Nothing should happen if we don't have views enabled.
  if (module_exists('views')) {
    views_include_handlers();
    module_load_include('inc', 'views', 'plugins/views_plugin_cache');
    $view = views_get_view($view);

    // We use the cache plugin to clear the cache, since that's probably the best idea.
    $cache_plugin = new views_plugin_cache();

    // The cache plugin does not care which display we are using when it clears the cache,
    // it will clear all caches related to this view anyway, so we can safely use any display.
    $cache_plugin
      ->init($view, $view->display[0]);
    $cache_plugin
      ->cache_flush();
  }
}