[Hummingbird] Remotely trigger "clear cache"

We have several sites using Hummingbird page caching and we want to find a method to easily trigger clearing the caches remotely. We want this because we push content to these sites through another plugin and the content is changed directly in the database, so the changed content isn't reflected in the cached version and doesn't trigger a clearing of the cache.

Either a URL parameter or a function would be useful for this. Does that capacity exist in Hummingbird?

  • Adam
    • Support Gorilla

    Hello Jade

    I hope you’re well today and thank you for your question!

    It can be done as Hummingbird includes a simple API that can be used to trigger cache. There’d be two ways of doing this. One is using an action hook “wphb_clear_page_cache” and the other one is to use REST API.

    The first method is pretty easy to use if you e.g. wan’t to trigger cache clearing from your own plugin that works on your site. All you’d need to do would be to execute that action in your plugin whenever you want to clear cache:

    do_action( ‘wphb_clear_page_cache’);

    This would clear all cache on site and following example would only clear cache for page/post of ID 10.

    do_action( ‘wphb_clear_page_cache’, 10 );

    That would only work “locally to the site” but depending on your needs it could also be used to trigger cache clearing remotely with a bit of additional custom code. What you’d want to do would be to write a simple plugin (and install it on all your sites) that would simply “listen” for some specific URL or URL query being requested and then execute that action. I hope that makes some sense :slight_smile:

    The other method, much more suitable for remote usage, is the REST API. There’s a REST API end-point built in that you can call. For example, to clear entire cache you’d want to call it like this:

    http://example.com/wp-json/hummingbird/v1/clear_cache/

    Take a look here, please:

    https://wpmudev.com/docs/wpmu-dev-plugins/hummingbird-api-docs/#chapter-5

    And here’s more about using REST API in WordPress:

    https://developer.wordpress.org/rest-api/

    I hope that helps :slight_smile:

    Best regards,

    Adam

  • Adam
    • Support Gorilla

    Hi Greg

    You can’t execute action this way in your code, by using “do_action()” funciton. This is what Hummingbird does and if you want to execute it you would need to use “add_action()” function with your callback function.

    The initial request in this ticket was quite specific and the code suggested was basically a “tip” for further custom development rather than “ready to use code”.

    But it seems that what you are trying to do is to clear cache “on schedule/interval”. There’s already a feature for that built-in into the plugin and you can set clearing cache regularly on scheduled via “Cache interval” option on “Hummingbird Pro -> Caching -> Page Cache” page.

    Please note though: this is nearly two years old ticket. If you have any follow-up or additional questions on this or you require more assistance, please open a new one here

    https://wpmudev.com/forums/forum/support#question

    describing the case and the goal that you wish to achieve and we’ll help you there.

    Best regards,
    Adam