How do I empty Drupal Cache (without Devel)

2019-04-03 07:32发布

How do I empty the Drupal caches:

  • without the Devel module
  • without running some PHP Statement in a new node etc.
  • without going into the database itself

Effectively, how do you instruct an end user to clear his caches?

12条回答
Anthone
2楼-- · 2019-04-03 08:22

I found the following at: http://www.drupalgardens.com/content/clear-all-caches-not-working

There's another layer of caching around the site which "clear all caches" does not affect, you're right. That's the layer that stores the content for anonymous users.

If you want to bypass the cache for testing purposes, you can add a junk query string to the end of your site path. For example, if you wanted to bypass the cache on example.drupalgardens.com/foo you could visit example.drupalgardens.com/foo?bar=baz or any other random text set up like ?xxxxx=xxxxx.

This helped me, because I have had issues where clearing the cache under Configuration > Performance didn't seem to help.

查看更多
The star\"
3楼-- · 2019-04-03 08:23

If you want to clear the cache from a module, you can use the following code.

drupal_flush_all_caches();
查看更多
萌系小妹纸
4楼-- · 2019-04-03 08:26

You can also use the Drush module, which allows you to use the command line to execute popular Drupal commands, like "drush cron" or "drush cache clear".

查看更多
Luminary・发光体
5楼-- · 2019-04-03 08:29

The above code is for Drupal 6.

For Drupal 7 the flush-cache module would be as follows:

<?php 
/**
 * Implementation of hook_menu()
 */
function flush_cache_menu() {
  $items = array();

  $items['flush-cache'] = array(
  'type' => MENU_NORMAL_ITEM,
  'title' => t('Flush the cache'),
  'description' => 'Flush all website caches to make sure it updates to relect '.
    'your recent changes.',
  'page callback' => 'flush_cache_custom_callback',
  'access callback' => user_access('flush cache'),
  );

  return $items;
}

/**
 * Implementation of hook_permission()
 */
function flush_cache_permission() {
  return array(
    'administer my module' => array(
      'title' => t('flush cache module'),
      'description' => t('Content admin flush cache.'),
    ),
  );
}

/**
 * Function that flushes the cache
 */
function flush_cache_custom_callback() {
  drupal_flush_all_caches();
  return 'Caches were flushed.';
}

Note: that you then flush it by going to:

sitename.com/flush-cache

Make sure you give them permission on the permission page. Clear cache once the "normal" way if the permission doesn't appear after turning the module on.

This is preferable when you don't want your client to get access to the admin menu but you still want them to be able to flush the cache.

查看更多
干净又极端
6楼-- · 2019-04-03 08:30

On-demand clearing can be done in Administer > Site Configuration > Performance.

You should setup the cron job to run every hour (or whatever interval to your liking).

When cron is run on Drupal, all caches are cleared and rebuilt without the need for a human to manually do it.

If this question pertains to theming, you should disable the caching mechanisms (css/js aggregation) and you won't have to clear the cache data when you make changes.

查看更多
我命由我不由天
7楼-- · 2019-04-03 08:30

The following module creates a menu item that is accessible only to users with the permission "flush cache", which this module makes available on the regular user permissions page.

/**
 * Implementation of hook_menu()
 */
function flush_cache_menu() {
  $items = array();

  $items['flush-cache'] = array(
  'type' => MENU_NORMAL_ITEM,
  'title' => t('Flush the cache'),
  'description' => 'Flush all website caches to make sure it updates to relect '.
    'your recent changes.',
  'page callback' => 'flush_cache_custom_callback',
  'access callback' => user_access('flush cache'),
  );

  return $items;
}

/**
 * Implementation of hook_perm()
 */
function flush_cache_perm() {
  return array('flush cache');
}

/**
 * Function that flushes the cache
 */
function flush_cache_custom_callback() {
  drupal_flush_all_caches();
  return 'Caches were flushed.';
}
查看更多
登录 后发表回答