Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Rather than wait for cron to trigger, it would be really great if the recache process could be triggered via hook_exit(), so that it happened instantly.
Comment | File | Size | Author |
---|---|---|---|
#19 | optionally_trigger-2828873-18.patch | 4.29 KB | Vacilando |
#17 | optionally_trigger-2828873-17.patch | 2.49 KB | Vacilando |
#14 | recacher-n2828873-14.patch | 9.46 KB | DamienMcKenna |
#7 | recacher-n2828873-7.patch | 2.67 KB | DamienMcKenna |
#2 | recacher-n2828873-2.patch | 2.36 KB | DamienMcKenna |
Comments
Comment #2
DamienMcKennaAs described. I need to test it a bit.
Comment #3
Vacilando CreditAttribution: Vacilando as a volunteer commentedHmm, good one. Thought of it as well, in fact posted some thoughts about immediate recaching in #2714211: Rules Integration / 3.
We could fire a re-caching request immediately as we detect a node change, or at hook_exit().
The problem I see is that at that moment caches *most probably* are not yet expired. Esp. any external cache (Boost, Varnish, Akamai, ...) needs a certain time to receive the purge requests and process them. If we fired our re-caching request so soon, we would probably still hit the old cache.
That said, I am happy to implement recaching on hook_exit() as an option. It probably will work for standard Drupal page caching (database), and maybe for local types of caching, such as Boost. I just doubt it can ever work like that when using Akamai / Varnish / Fastly / ...
What do you think, @DamienMcKenna? Please correct me if I am wrong.
Comment #4
DamienMcKennaYou bring up an excellent point. The site we want to use it with runs cron every minute, so we're going to start with hook_cron() and look into further optimizations later as needed.
Comment #5
DamienMcKennaProbably needs some tests too.
Comment #6
Vacilando CreditAttribution: Vacilando as a volunteer commentedDoes not apply to the current dev; could you do a quick re-roll?
Comment #7
DamienMcKennaRerolled.
Comment #9
Vacilando CreditAttribution: Vacilando as a volunteer commentedCommitted to 7.x-1.x-dev. Needs the tests -- and testing before we can close this issue.
Comment #10
Vacilando CreditAttribution: Vacilando as a volunteer commentedChanged the checkbox that added caching via the exit hook to a radio button, so that the exit hook and cron become alternatives. Also made sure that the cron hook does not get executed if the exit hook is selected. Already committed to 7.x-1.x-dev. Is backward-compatible.
Comment #11
Vacilando CreditAttribution: Vacilando as a volunteer commented@DamienMcKenna -- some comments:
If you do any improvements please provide a patch based on the current dev. Thanks!
Comment #13
DamienMcKennaI'm on vacation until January, I'll try to review the feedback then,
Comment #14
DamienMcKennaYeah, moving the drupal_static make sense.
It might be better to not disable hook_cron() if hook_exit() is being used. At the same time it might be worthwhile adding a lock around it so that there isn't any stampeding. I've added a patch that adds this functionality.
Comment #16
Vacilando CreditAttribution: Vacilando as a volunteer commentedThanks, @Damien!
Had to change lock_acquiare() to lock_acquire(), LOL :-)
Committed to 7.x-1.x-dev.
Testing both the scheduled and immediate caching. Please test this also on your side before I roll a new stable release.
Comment #17
Vacilando CreditAttribution: Vacilando as a volunteer commentedAdded a test to see whether there are any modules implementing hook_recacher_role_options(). Without this test, variable $recacher_role_options was being emptied.
See patch. Committed to 7.x-1.x-dev.
Comment #19
Vacilando CreditAttribution: Vacilando as a volunteer commented@Damien: I understand why you prefer not to disable hook_cron() if hook_exit() is being used.
What worries me is that after hook_exit() runs, even if it is not successful, it will clear the URLs from the queue, meaning hook_cron() will never get a chance to pick them up.
Therefore I propose to allow URL deletion from the queue only when hook_cron() runs.
hook_exit() may try to re-cache even earlier (if switched on at the config page), but will not delete the URLs it crawled.
The only disadvantage of this approach is that if hook_exit() manages to achieve the recrawl, then hook_cron() will do nothing. On the other hand, it will be a very fast and cheap call hitting the cache.
Patch attached, code committed to 7.x-1.x-dev!
Comment #20
Vacilando CreditAttribution: Vacilando as a volunteer commentedSeems to work perfectly for me. What hook_exit() does not catch is cached by hook_cron(). Test OK.
Comment #21
Vacilando CreditAttribution: Vacilando as a volunteer commentedSeems stable; marking as fixed. If you see any issues, don't hesitate to reopen.
Comment #22
Vacilando CreditAttribution: Vacilando as a volunteer commentedNow also in 7.x-1.2.
Comment #24
DamienMcKenna(just catching up after two months of email overload) Thanks for all the improvements, @Vacilando!
Comment #25
Vacilando CreditAttribution: Vacilando as a volunteer commentedHey this is thanks to your report and a great initial patch DamienMcKenna ✓