2

I'm running Drupal 7.25 on my Ubuntu server. I have a process that is kicked off by user interaction (form) that needs to run in the background. I currently have cron.php being run every minute via crontab. I read this article:

http://www.metaltoad.com/blog/how-drupals-cron-killing-you-your-sleep-simple-cache-warmer

Does running cron.php still clear cache in D7?

1
  • A lot of modules use "lightweight cron" which only do specified lightweight tasks if you have something that needs to be checked every minute. Check out the Scheduler module.
    – Beebee
    Commented Jan 6, 2014 at 17:24

2 Answers 2

3

Yes, running cron.php still clear cache, as running the cron will call system_cron which calls "cache_clear_all" method:

$cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
foreach ($cache_tables as $table) {
  cache_clear_all(NULL, $table);
}
1
  • Thanks! Now I can set back my crontab so I'm not killing my site every minute ;)
    – Ken J
    Commented Jan 6, 2014 at 16:57
10

If you take a look at system_cron(), you will see

$cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
foreach ($cache_tables as $table) {
  cache_clear_all(NULL, $table);
}

Reading the docs for cache_clear_all($cid, $bin):

$cid: If set, the cache ID or an array of cache IDs. Otherwise, all cache entries that can expire are deleted. The $wildcard argument will be ignored if set to NULL.

This means that a full cache clear won't be done, but entries that are older than their TTL are removed from the cache.

However, {cache_page} uses CACHE_TEMPORARY for the TTL (see drupal_page_set_cache(), so these will be removed each cron run. Though the code support it, I have never seen anything other that a -1 in the exipres column in {cache_page}, no matter what the TTLs on the performance settings are.

2
  • 2
    Everyone interested should read the comments at metaltoad.com/blog/…, search for the comment "This is incorrect. This call" by Moshe Weitzman. Commented Dec 30, 2015 at 20:34
  • This answered my question as to why my cache wasnt expiring even with low values, without running cron.... Commented Mar 9, 2016 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.