Email
Share

We Rock Your Web Forum » Content Management Systems » Drupal

Clear cache page for Drupal?

(3 posts)
  1. obelix

    member
    Joined: Jul '09
    Posts: 15

    Is there any way to simply create a page in Drupal, that, when loaded - will clear specified cache tables? I know there's all kinds of caching and cron modules out there - but all I really need is for a client to access a simple cache setting every now and then, that will clear out the cache on a button press or page load, etc.

    Posted 1 year ago #

  2. Posted 1 year ago
  3. Anonymous



    You can create a "clear cache" page in Drupal as follows. Note that you'll need to set the input format to PHP (the creator of the page needs this permission, not the one loading or viewing it). I also recommend installing the path access module - and disallowing the role "anonymous user" from accessing your clear cache page (make sure you allow "authenticated user" - otherwise your other roles will get "access denied" messages, since they are also considered authenticated users.

    <?php
    /*
    * Based on devel_cache_clear() function from devel module.
    */
    // only allow site administrators to visit this page:
    if (!user_access('administer site configuration')) {
    drupal_not_found();
    }
    else {
    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();
    }
    ?>

    Changes you can make to this code for customization purposes:

    • You can remove the !user_access('administer site configuration') line, or change the permission action, according to the access permission you wish to set.
    • You can add/ remove caching tables (especially for newer versions of Drupal, since they use additional caching tables).

    Posted 1 year ago #
  4. Anonymous



    Good solution, thanks. In Drupal 6.x you can simply use drupal_flush_all_caches();

    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.