BoldGrid / w3-total-cache

GNU General Public License v2.0
152 stars 85 forks source link

Scheduled events permanently go missing from cron #537

Open smerriman opened 2 years ago

smerriman commented 2 years ago

Every so often, one of my clients' sites starts having cache-related issues, showing old content.

I check the list of cron tasks, and W3 Total Cache's events (eg w3_pgcache_cleanup) are completely missing from the list, so the plugin is often serving week-old HTML rather than cleaning them up hourly as per the default settings. Deactivating and reactivating the plugin resolves the issue - at least until a few months down the track when it may reoccur.

Cron jobs going missing is an oft-reported problem - usually caused by some glitch where a task doesn't complete properly and thus core WordPress doesn't reschedule it).

While you could consider this an issue with WordPress core's cron logic, almost all other plugins solve this by running a quick hook that checks if the cron job exists, and if not, rescheduling it, rather than only doing this on plugin activation. Is this something you can do as well?

mavas84 commented 2 years ago

Hello @smerriman

Thank you for reaching out and I am happy to help. If the old content is being served, it means that the cache is not purged. The Purge Policy in Performance>Page Cache lets you specify the pages and feeds to purge when posts are created, edited, or comments posted. Once the content of the page is changed or a new post is published, the cache should be purged automatically. Thew3_pgcache_cleanup is for the Garbage collection interval which, If caching to disk, specifies how frequently expired cache data is removed. This means that this cron does not clear the cache but removes the old cache (_old files in the cache folder) once the cache is purged. Once the page is cached, it's serving the same cache until the cache is purged, so just to understand, can you please specify that the cache is not purged once the content is changed or that you think the w3_pgcache_cleanup suppose to clear the cache every hour?

Thanks!

smerriman commented 2 years ago

The point here is that the cron events are required for the plugin to work correctly. If they ever go missing due to a WordPress glitch, the plugin never re-adds them unless deactivated and reactivated.

This glitch can often happen in WordPress, so other plugins often check for wp_next_scheduled in a hook like wp / init and reinstate the event if it's not found, ensuring it's always in place.

mavas84 commented 2 years ago

Hello @smerriman

https://github.com/W3EDGE/w3-total-cache/blob/2.2.3/PgCache_Plugin.php#L45-L46 and https://github.com/W3EDGE/w3-total-cache/blob/2.2.3/PgCache_Plugin.php#L164-L189 are for PgCache WP-Cron schedule. They return schedules for garbage collection and priming cache every pgcache.file.gc andpgcache.prime.interval seconds. The automated tests did pass for garbage collection. I've checked with the team, and the devs will look into the crons and review your suggestion.

Thanks!

smerriman commented 1 year ago

This is still occurring. Another email from a client, another case of the cron events not existing. Had to deactivate + reactivate the plugin once more.

Any progress here?

smerriman commented 1 year ago

No response. This is still occurring.