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条回答
姐就是有狂的资本
2楼-- · 2019-04-03 08:07

I have the easiest solution for that. Install admin_menu module (actually not only for this purpose, once you have installed this module, you wont regret it for sure, link: http://drupal.org/project/admin_menu). Ok, then on a newly appeared top dropdown menu hover your favicon and dropdown menu will appear, and you will see: Flush all caches menu. One click - one flush. Moreover you can flush all caches together or select what to flush: Pages, menu, themes etc. Try and you will never go back )

查看更多
对你真心纯属浪费
3楼-- · 2019-04-03 08:07

HERE YOU GO:

I had to de-install the "devel" module (it was incompatible with Special Menu Items, which I needed worse), so I made my own.

Anywhere you see MODULENAME replace it with the name of your module.

STEP 1: Add to any module (preferably one of your custom modules) in the HOOK_MENU, before the "return $items" line:

// short cut for flushing the caches:
$items['flush-cache'] = array(
  'type' => MENU_CALLBACK,
  'title' => t('Flush the cache'),
  'description' => 'MODULENAME Custom Cache Flush',
  'page callback' => 'MODULENAME_flush_cache',
  'access callback' => TRUE,
);

STEP 2: Now, in the same module file, where it's not "inside" any other function, add:

/**  Page callback  **/
function MODULENAME_flush_cache() {
  drupal_flush_all_caches();
  return 'Caches were flushed.';
}

Now, you can just go to the URL "/flush-cache" on your site to flush the cache. (After you flush the cache one last time the old way.)

STEP 3: If you want it REALLY convenient, add the following to your page.tpl.php file. You can put it pretty much anywhere between <body> and </body>. NOTE: $my_is_test is a variable I use that's TRUE on my test system, and FALSE in production. If you don't have something like that, replace it with TRUE or FALSE to turn it on or off:

<?php if ($my_is_test): ?>
<a style="text-align:left; position:absolute; right:2px; top:20px;" href="<?=$base_path?>flush-cache" onclick="this.innerHTML = '<b><blink><big>Wait...</big></blink></b>';">flush</a>
<? endif; ?>

And voila! You have a "flush" link at the top-right corner of every page you can click on. Feel free to change the "right" and "top" amounts (or change "right" to "left" or "top" to "bottom" to put it wherever you like it. This link positioning only works on modern browsers, but it's only for you, so it shouldn't be a problem, right?

查看更多
迷人小祖宗
4楼-- · 2019-04-03 08:11

When you are logged as an admin (obviously, not every user of the site has to power to clear the cache), there should be a page in "Administer > Site Configuration > Performance".

And, at the bottom of the page, there should be a button (something like "Clear cached data") to clear the cache

As far as I remember, there's no need for Devel to do that, and you really don't need to go to the database, nor run some home-made PHP code.


As a reference, you can take a look at How to Clear Drupal Server-side cache

查看更多
啃猪蹄的小仙女
5楼-- · 2019-04-03 08:16

use drush and this command: drush cc all

If you're using Boost to cache you need to be more specific:

drush @alias_name cc all
查看更多
兄弟一词,经得起流年.
6楼-- · 2019-04-03 08:19

It would be awesome if you could just GET the behavior by hitting:
http://drupal.local./admin/settings/performance?op=Clear%20cached%20data
but you can't.
However I do want to note the URL for short-cutting through the admin menu (use the latter part):
http://drupal.local. /admin/settings/performance

查看更多
祖国的老花朵
7楼-- · 2019-04-03 08:21

In Drupal 8, the admin menu module isn't quite ready for use yet. And it will probably get replaced with Drupal "Toolbar". So right now there's no easy way to clear cache, without actually going to:

admin/config/development/performance

The only alternative is to add a menu item in the existing toolbar. This can be done by using this module, but as you can see, it still needs a bit of work. I got it working, but had to make a few tweaks.

查看更多
登录 后发表回答