I have block caching enabled on a drupal 6 site. I would like to clear this cache out about every 3 hours using cron, but I have no idea what command I should run. Any ideas what command I could put in my crontab to accomplish this?

Since I am only running the command every 3 hours it would not be a problem if I cleared all of the caches. So if you can think of a command that does the equivalent of clicking on the "Clear cached date" button on admin/settings/performance -- that will work just as well.

Comments

Shai’s picture

Hi jeeves,

You don't write a new cron tab. Just one cron tab per Drupal site is all you need.

What you do is write a small custom module and invoke hook_cron. When the cron job runs, it flushes the caches. Here is a module I wrote for this purpose:

<?php
// $Id$

/**
 *@file
 * Custom module for site.
 */

/**
 * Implementation of hook_cron.
 * Flush all caches.
 */

function custommodulename_cron() {
  drupal_flush_all_caches();
}

Put that in a file called custommodulename.module.

You need to create an .info file called costommodulename.info

That file might look like this:

; $Id$ 
name = Custom Module Name
description = Customizations for site.
core = 6.x
package = Custom

Of course, replace custom module name references with a better name. I usually use a short version of the site name there.

You put the two files in a directory with the custom module name. You put the two files in that directory and put them in your sites/all/modules/ directory. And you turn it on like any other module.

NOTE: I think the regular old cron without a custom module flushes some of the caches, for sure the "page" cache. It might flush the block cache as well. This module flushes all caches.

p.s. This is for Drupal 6 or 7

best,

Shai
Content2zero