In hook_flush_caches() there is a piece of logic that checks if it was called by cron. It does this by checking lock_may_be_available('cron').

The problem with that approach, is that it spans across requests. So whenever cron is running, hook_flush_caches() will not flush, regardless of being called from cron or not.

Perhaps a better approach could be to check $_SERVER['PHP_SELF'] for 'cron.php'?

Members fund testing for the Drupal project. Drupal Association Learn more


gielfeldt’s picture

Status: Active » Needs review
2.76 KB

Here's a patch...

bgm’s picture

Can you give more information on how lock_may_be_available('cron') may span across requests?

Does checking for cron.php explicitely also work when the cron is called from drush?

Thanks for the patch.

gielfeldt’s picture

Hi bgm

One of the main purposes of a lock/semaphore is that it's available across requests, so one may take concurrency into consideration. The lock is stored in the DB (or memcache or other backend). It's available to whoever asks for it. So if cron is running, and you then invoke the flush_caches, then Boost will not flush its caches, because it thinks cron is running ... because cron __is__ running, just in another request.

The patch didn't support Drush, well spotted. I've added a new patch that supports Drush as well.

gielfeldt’s picture

Any news on this?

heddn’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

It works. I tested both with drush and cron.php on a fairly complicated site that also has boost installed.