Problem/Motivation

#2143249: Remove legacy cache_clear_all() in cron removed cache_clear_all() from scheduler_cron(). But in some cases, it is actually useful. For example: you enabled page cache for anonymous users and configured Elysia Cron Module to run system_cron less frequent than scheduler_cron.

Proposed resolution

The same as originally proposed in #2143249: Remove legacy cache_clear_all() in cron: add an option to still call cache_clear_all().
Make it unchecked by default to provide seamless backwards compatibility.

User interface changes

On admin/config/content/scheduler you get a checkbox labeled 'Upon publish or unpublish, clear all expired block and page caches.'.

API changes

A new variable, called scheduler_cache_clear_all.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

PieterDC’s picture

Assigned: PieterDC » Unassigned
Status: Active » Needs review
FileSize
6.53 KB

Attaching patch. Includes: test coverage, an admin UI form element, a Drupal variable with a default value and removal at module uninstall.

Status: Needs review » Needs work

The last submitted patch, 1: clear_page_cache_on_scheduler_cron-2377201-1.patch, failed testing.

jonathan1055’s picture

I think the testbots are having trouble. I have seen this error on a different project an hour ago. I don't think it's anything to do with your patch.

I will test your patch and review it. Thanks

PieterDC’s picture

Test fails because of an error reported in #2375345: Dependency on core module results in PHP Fatal error: Cannot redeclare system_requirements().
Set this issue back to 'Needs review' once the blocking issue is fixed.

jonathan1055’s picture

Also, just to let you know, we had a major effort to get all existing 7.x issues and patches committed before we released 7.x-1.3. The one issue remaining which was too dangerous to rush through is #2170353: Reduce memory footprint which is going to be the next commit as it touches the whole of .module. If we commit anything else before that one, then it will need constant re-rolls, so we decided that this will be the first, and any other patches can then be re-rolled.

jonathan1055’s picture

Just an idea, are you using the lightweight scheduler cron to have cron run more often than the full cron? If so, we could just add the cache_clear_all() in to function _scheduler_run_cron(). Maybe we should do that anyway, now that it's not done in scheduler_cron()?

PieterDC’s picture

No, we're not. We use Elysia cron to configure cron task frequencies. The Scheduler lightweight cron doesn't show up in that list.

But you're right, using the lightweight scheduler might be another use case. So maybe we should extend the description of the provided checkbox to include an explanation that you're advised to use this new feature if you use Scheduler lightweight cron.

jonathan1055’s picture

Issue summary: View changes

This looks good.

.install - all ok

.module - need to adjust the text as per #7 above. The checkbox gets a bit lost on the page, having no title, but that's not your fault. However, I can't see it would be better in any other place on the form.

.test - you've done a lot of work here. Particularly, you have changed the way we test for the basic published/unpublished node by going to the node and testing for response 403, instead of asserting that node body text is not on the front page. I like that. Thanks also for documenting the @param descriptions. These early tests were written by neither of the current maintainers - we'd always add descriptions ;-)
I'm not sure we need such an amount of detail about Elysia Cron in the .test file. You can reference this issue to give background for future maintainers.

The above is only one opinion, I'd like Pfrenssen's view on this too.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: clear_page_cache_on_scheduler_cron-2377201-1.patch, failed testing.

The last submitted patch, 1: clear_page_cache_on_scheduler_cron-2377201-1.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: clear_page_cache_on_scheduler_cron-2377201-1.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: clear_page_cache_on_scheduler_cron-2377201-1.patch, failed testing.

Status: Needs work » Needs review
bertramakers’s picture

I reviewed this as part of a bigger (internal) ticket that I'm working on with PieterDC where we work, and the patch seems fine to me as well.

I agree that the example explanation of Elysia cron might be unnecessary, but I'll let you guys decide about that.

But if I understood correctly this will need to be re-rolled after #2170353: Reduce memory footprint is committed, so we'll need to follow this up later.

Not setting this to RTBC so we can await Pfrenssen's opinion if he wants to pitch in.

jonathan1055’s picture

Status: Needs review » Needs work

Hi bertramakers, yes you are right, the code split patch was always going to be the first commit after releasing 7.x-1.3. That has now been done so you can re-roll your patch.

iSoLate’s picture

Status: Needs work » Needs review
iSoLate’s picture

This seems to apply and do the trick still.

jonathan1055’s picture

Hi iSoLate,
The patch applies OK to the release 7.x-1.3 but it no longer applies to the 7.x-dev code, as per the comments in #17 and #18. I cannot find a way to re-queue the existing patch, maybe because testing is no longer done on qa.drupal.org and has been superseded by DrupalCI.

Hence I have re-added the same patch from #1 here, to see what happens.

Status: Needs review » Needs work

The last submitted patch, 21: 2377201-1.clear_page_cache_on_scheduler_cron.patch, failed testing.

jonathan1055’s picture

As expected the existing patch does not apply. Here's a re-rolled version for the latest 7.x-1.x-dev code. I moved the new checkbox into the lightweight cron tab, as it is only really required when not running the full cron.

This feature will have to be added to the 8.x code first.

pfrenssen’s picture

This has its use case on Drupal 7. It's a bit of a shotgun approach, and it's not _really_ Scheduler's responsibility and a bit of an edge case, but I can understand that this can be useful in situations such as explained in the issue summary. Since it is disabled by default this does not harm anyone.

In Drupal 8 this should not be needed. Thanks to the adoption of cache tags if a piece of content is published or unpublished, all related cache entries will automatically be invalidated. There is luckily never a need to do a full cache clear on a production instance on Drupal 8.

+++ b/scheduler.admin.inc
@@ -404,6 +404,12 @@ function _scheduler_lightweight_cron($form, &$form_state) {
+  $form['scheduler_cron_settings']['scheduler_cache_clear_all'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('After publishing or unpublishing during cron, clear all expired block and page caches.'),
+    '#default_value' => variable_get('scheduler_cache_clear_all', 0),
+    '#description' => t('Makes the Scheduler cron task clear caches instead of relying on the Drupal core System cron task.'),
+  );

I would add a warning here that enabling this can have a serious impact on performance.

jonathan1055’s picture

Status: Needs review » Fixed

Thanks @pfrenssen for the explanation about Drupal8 tags. I was hoping that this was not going to be required in 8.x
I added a warning as you suggested. The full description is now

If a node has been published or unpublished by Scheduler during a cron run, this option will clear the caches instead of relying on the Drupal core system cron task. Warning: This may have a detrimental effect on performance for large sites.

Thank you @PieterDC for the initial patch. Committed and fixed (although the auto-comment for the commit has not shown up yet).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.