WP Discourse comment webhook does not trigger a WP Rocket Cache refresh

How do we handle page caching in Wordpress?

I use WP-Rocket on our site, but page caching (same issue if only using Cloudflare APO) is preventing the comment count from updating. I verified this by disabling WP-Rocket (and/or APO), posted a reply on the corresponding forum post and the comment count updates, but erratically. As in, not instant or as you might expect.

So I found a tip on adding a web hook and that allowed the comment count to reliably update.

However, with page caching on (WP-Rocket or APO), and using that web hook, the comment counts are not updating when someone posts a new reply in the forum.

The gist, it seems, the web hook is not triggering the WP environment properly to trigger the refresh of the cached page. It seems we might have a glitch in the matrix. :smile:

Edit: Another bit. I have WP-Rocket setup so when I am logged into Wordpress, the pages are not cached for me. Only for visitors. I noticed, I see comment counts update when I am logged into Wordpress, but I do not see them when I am a visitor in private browser mode.

1 Like

I don’t have any answers, but as you know WP Rocket is trying to do a static copy and eliminate PHP and database calla. It is not a cache per se, but sure — that is matter of definition.

But WP Rocket has a lot issues nowadays, and this is perhaps one of the most minor ones when thinking WordPress site itself.

Well, that way it should work.

Hey @Brandon007, thanks for explaining your issue. As I understand it:

  • The WP Discourse Plugin is updating comment counts correctly.
  • The WP Rocket cache is not being cleared when the comment counts are updated.

I’ve changed the title of your post from “WP Discourse Plugin Not Updating Comment Count” to “WP Discourse comment webhook does not trigger a WP Rocket Cache refresh”.

The basic answer to your issue is that this is expected behavior. The WP Discourse plugin doesn’t have any specific integration with WP Rocket and won’t be adding one in the foreseeable future.

But I can still help you here by adding in an action that fires after the comment sync webhook callback has updated the topic metadata (where the comment count is stored). You could then write your own action callback to do whatever cache clearing you desired. Would that work for your situation?

3 Likes

@Angus you got it!

I’ll probably be lost writing code haha, but if you can make it possible. That puts me and other users one step in the right direction. It sounds like, with your modification it will allow user end code to be added to clear caching for any caching plugin. That would be even better than focusing on one product. I tried several cache methods on a dev site and they all had the same result anyway.

So carry on my good sir, and thanks for the response.

Hey Angus. I’m not sure if this was something you were still looking into?

Something else I wanted to add. Within native Wordpress, and using any form of page caching. Once a comment is left, the page cache purges on its own. Isn’t there a way where WP Discourse can mimic that behavior?

Not with WP Rocket. It keeps comments dynamic, as it should.

Hey Brandon, yes there will be an action for this, allowing you to clear the WP Rocket cache (or any other cache) in this scenario in the next release.

I’m not questioning your or anybody’s skills and I don’t know anything, but there can’t be anything like ”or any cache” because AFAIK WP Rocket needs different tools to purge its caching than W3 Total Cache than WP Fastest Cache than any reverse proxy like Varnish or Nginx.

And if WP Rocket is creating static part of page, aka. cache, from comment section there is much bigger issues than purging.

That’s correct. The WP Discourse plugin will simply provide an action that will allow sites using different caching solutions to purge the cache at the appropriate time using whatever method is appropriate to the caching solution being used.

1 Like

Angus, thanks for the follow-up. Any general idea on the release date?

Also, is it possible for WP-Discourse to mimic the behavior of native Wordpress comments? Simply meaning, page cache solutions have an option, so the page cache can be cleared when a user leaves a new comment on that page. This is ideal.

As you know, as of today, we are unable to use page caching of any kind, if we want the comment count to increment. That’s a big drawback for Wordpress users who are concerned with speed optimizations.

Hopefully not, because such behaviour would be awful waste of resources and actually close to be a deal breaker.

I’m still a bit confused because natively WordPress hasn’t caching and WP Rocket defenetly not purge whole its so called caching after a comment.

Just a note that the action I’ve mentioned above will be added in 2.4.6 which is currently being prepared for release.

The action will receive the ids of the Wordpress posts that have been updated by the webhook as an argument, i.e.

do_action( 'wpdc_after_webhook_post_update', $post_ids );

See further

2 Likes