• I’m the author of the speechkit plugin. The plugin calls a third party (https://speechkit.io) to generate audio and then sets up a cron job to wait for it to finish, polling every minute to see the status. Once the audio is ready, the plugin renders a player in the post. However with the litespeed cache plugin, it’s not showing up. I’ve tried to purge the cache of a specific post (unsuccessfully) with the following code:

    if (function_exists('purge_single_post')) {
      purge_single_post($post_id);
    }

    From the method documentation for purge_single_post in litespeed-cache it reads: “If a third party plugin needs to purge a single post, it can send a purge tag using this function.”

    What am I missing?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    Hi @speechkit

    I am assuming that you are trying to purge the post during the cron job.

    Does your cron follow the typical WordPress loop? We depend on the shutdown action to send the header to the server to properly purge the cache.

    If so, you could also try one of our other hooks/functions to see if it works:

    
    if (class_exists('LiteSpeed_Cache_Tags')) {
        LiteSpeed_Cache_Tags::add_purge_tag(LiteSpeed_Cache_Tags::TYPE_POST . $post_id);
    }
    

    In our plugin settings, you can also enable debug log to check your modifications. This will output the response headers sent out during the request. You are looking for an ‘X-LiteSpeed-Purge: ‘ header.

    Cheers,
    Kevin

    Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    Quick question – did you try to use the purge_single_post as global function? It’s actually a function inside one of our classes.

    It should instead be something like:

    
    if (class_exists('LiteSpeed_Cache')) {
        LiteSpeed_Cache::get_instance()->purge_single_post($post_id);
    }
    

    Kevin,

    Thanks for your swift reply. The plugin has 2 flows into purging the cache, one would be through WPs cron loop and the other is on an ajax call made manually from a user by pressing a button in the admin panel.

    By calling the add_purge_tag will it be “queued” for the next request? Having some trouble understanding how this is suppose to work with the cron job.

    I will try what you recommended to see if it helps and report back here.

    I did indeed use it as a global function. It makes more sense that it’s name spaced under the LiteSpeed_Cache plugin. What seems to have worked with the w3tc plugin is doing something similar but calling a public function named w3tc_flush_post, so I assumed this would be similar.

    I will try the second recommendation you had as well and report back.

    Thanks again

    Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    So the caching logic itself is in the LiteSpeed server itself. This WordPress cache plugin is strictly used to communicate what to do with the cache entries.

    Using the WP cron as an example, the request should hit the server first then go to WordPress. You do your thing and it adds a X-LiteSpeed-Purge header using our API. The response header is then processed by the server, and the server will purge the related post and the response is sent out to the client.

    add_purge_tag will add the tag to the current request and the X-LiteSpeed-Purge header should contain the built purge tag.

    I hope this clarifies things, let us know if you have more questions, we’ll be glad to help!

    Cheers,
    Kevin

    I just tried out:

    if (class_exists('LiteSpeed_Cache')) {
        LiteSpeed_Cache::get_instance()->purge_single_post($post_id);
    }

    And it worked!

    What is confusing about this is that I couldn’t find a method named get_instance on the LiteSpeed_Cache class.

    Thank you for all your help.

    Plugin Support Hai Zheng?

    (@hailite)

    Hi @speechkit,

    get_instance is in the bottom of LiteSpeed_Cache class.

    Plugin Support Hai Zheng?

    (@hailite)

    Also, we added a new function which you can directly use in v1.2 which will be released in couple weeks: litespeed_purge_single_post().

    You can use

    if (function_exists('litespeed_purge_single_post')) {
      litespeed_purge_single_post($post_id);
    }

    Awesome,

    Thanks for the heads up. I’ve now added:

    
    if (function_exists('litespeed_purge_single_post')) {
      litespeed_purge_single_post($post_id);
    } else if (class_exists('LiteSpeed_Cache')) {
      LiteSpeed_Cache::get_instance()->purge_single_post($post_id);
    }
    

    Which I’m hoping will take care of versions below and above 1.2

    Plugin Support Hai Zheng?

    (@hailite)

    Hi @speechkit,

    Please note that in v1.2, we are planning to enroll a new class for API calls, which is LiteSpeed_Cache_API. At that time, LiteSpeed_Cache::get_instance()->purge_single_post() will be moved there. We will introduce the details in docs later.

    Thanks,
    Hai

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Plugin author trying to purge cache for specific post’ is closed to new replies.