<?php

/**
 * @file
 * Quick Cache Cleaner Module
 *
 * This module allows authorized users to quickly clear all
 * Drupal and Views caches.
 */

/**
 * Implements hook_perm().
 */
function quick_cache_cleaner_perm() {
  return array('clear all caches');
}

/**
  * Implements hook_menu().
  */
function quick_cache_cleaner_menu() {
  $items = array();
  $items['admin/settings/cache-clear'] = array(
    'title' => t('Clear caches'),
    'page callback' => 'quick_cache_cleaner_invoke',
    'access arguments' => array('clear all caches'),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

/**
 * Callback to clear all caches.
 *
 * Invokes a views cache clear and then Drupal system cache clear.
 * Redirects to admin/settings on completion.
 */
function quick_cache_cleaner_invoke() {
  if (function_exists('views_invalidate_cache')) {
    views_invalidate_cache();
  }
  drupal_flush_all_caches();
  drupal_set_message(t('Caches cleared.'));
  drupal_goto('admin/settings');
}
