Email
Share

We Rock Your Web Forum » Content Management Systems » Drupal

Drupal Clear Cache Page?

(2 posts)
  1. idefix

    member
    Joined: Aug '09
    Posts: 17

    Is there a way for me to create a page in Drupal that will allow me to clear the cache by simply visiting that URL (ie. example.com/clear-cache)?

    This would be a great time saver over having to load cPanel & phpMyAdmin everytime I want to clear some cache out.

    Posted 1 year ago #

  2. Posted 1 year ago
  3. cwd

    senior admin
    Joined: Jul '09
    Posts: 225

    Yes, you can - although in Drupal 6+ you have a built in admin menu item for this if you install the "admin menu" module. It's called "Flush Cache," and also lets you flush individual cache tables.

    If you're using Drupal 5.x or lower, simply use the following code, ensuring first that the tables referenced in the $tables = array are present in your particular Drupal version. Finally, make sure you set your "input format" to PHP, and that you have the appropriate permissions set restricting access to this page (if only authorized users have the PHP input format permission, you should be fine).

    <?php
    /*
    *
    * function <code>devel_cache_clear()</code> from devel module.
    *
    */
    
      drupal_clear_css_cache();
      $tables = array(
        'cache',
        'cache_content',
        'cache_filter',
        'cache_menu',
        'cache_page',
        'cache_views',
      );
      foreach ($tables as $table) {
        cache_clear_all('*', $table, TRUE);
      }
      drupal_set_message('Cache cleared.');
      drupal_goto();
    ?>
    Posted 1 year ago #

RSS feed for this topic

Reply

(required)

Allowed markup: BBcode blockquote code em strong ul ol li font strike center u hr.
You can also put code in between backtick ( ` ) characters.