You are here

function cache_actions_action_clear_views_display_cache in Cache Actions 7

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

This action clears the cache of a specific view display.

Parameters

array $views the views to clear.:

1 string reference to 'cache_actions_action_clear_views_display_cache'
cache_actions_rules_action_info in ./cache_actions.rules.inc
Implementation of hook_rules_action_info().

File

./cache_actions.rules.inc, line 641
This file provides the rules integration for this module.

Code

function cache_actions_action_clear_views_display_cache($views) {
  if (module_exists('views')) {
    $loaded_views = array();
    views_include_handlers();
    module_load_include('inc', 'views', 'plugins/views_plugin_cache');
    if (is_array($views)) {
      foreach ($views as $entry) {
        list($view_name, $display_id) = explode(':', $entry);

        // Let´s make sure we don't load views unnecessarily.
        if (!isset($loaded_views[$view_name])) {
          $loaded_views[$view_name] = views_get_view($view_name);
        }

        // Check to see that the display has a caching plugin. If it doesn't add the default caching plugin.
        $display = $loaded_views[$view_name]->display[$display_id];
        if (!isset($display->display_options['cache']['type'])) {
          $display->display_options['cache']['type'] = $loaded_views[$view_name]->display['default']->display_options['cache']['type'];
        }

        // And then clear the cache.
        _cache_actions_clear_view_display($loaded_views[$view_name], $display);
      }
    }
  }
}