Support » Plugin: LiteSpeed Cache » How to trigger a cache purge from another plugin?

  • Resolved Raul P.

    (@alignak)


    Hi, just a quick question.

    How do I trigger a complete cache purge from within another plugin?

    For example, for W3TC I can do this:

    # Purge WP Super Cache
    if (function_exists('wp_cache_clear_cache')) {
        do_action( 'wp_cache_clear_cache' );
    }

    Is there a similar method I can use on your plugin?

    Kind Regards,

    Raul Peixoto

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

    (@litespeedtech)

    Hi @alignak

    Our list of third party functions are in litespeed-cache/includes/class-litespeed-cache-tags.php

    If you are looking to purge everything on the site, you can do

    
    if (class_exists('LiteSpeed_Cache_Tags')) {
        LiteSpeed_Cache_Tags::add_purge_tag('*');
    }
    

    However, if you’d like, you can also tag pages with an identifier so that you can take advantage of the smart purge feature.

    When you know a page has a certain feature, you can tag it. E.g. a gallery plugin might know a page has gallery id 4. They would do:

    
    if (class_exists('LiteSpeed_Cache_Tags')) {
        LiteSpeed_Cache_Tags::add_cache_tag('g.' . get_gallery_id()); // adds g.4
    }
    

    Then later, when they need to purge:

    
    if (class_exists('LiteSpeed_Cache_Tags')) {
        LiteSpeed_Cache_Tags::add_purge_tag('g.' . get_gallery_id());
    }
    

    Let me know if you have any more questions about this! We have a wiki article here, but I can also answer any questions here.

    Cheers,
    Kevin

    Thank you very much,

    My plugin is the fast velocity minify and it does merging of js and css files.
    When those files are purged, other cache plugins need to be purged completely also, so for my case I really need to purge everything.

    This is exactly what I needed, thanks.

    Raul

    Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    Ah, someone just asked about your plugin!

    If you’d like, we can validate your modifications and add your plugin to our list of compatible plugins when it’s available.

    Let us know if you run into any problems!

    Cheers,
    Kevin

    Indeed, someone also requested for you plugin to be supported too.

    I’ll be adding support on the next version so that purging my plugin will also purge yours too.

    It should be up within 24 or 48 hours and I’ll let you know if you wish to take a look and test things.

    Thanks again, Raul

    Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    Perfect, thanks!

    Hi Kevin,

    I’ve implemented this a while back and Fast Velocity Minify is already purging LiteSpeed Cache when “our” purge cache button is pressed.

    I have a function to purge our cache too, but I don’t think it’s relevant for your plugin, since it purges the whole cache only.
    Also, if I trigger the cache purge to your plugin, it would “double purge” mine… so I think we can leave things as they are.

    Thanks for the earlier tip on how to purge your cache.

    Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    Hi Raul,

    Good to know that it’s working! Thanks for your efforts on getting our plugins working together, I’ll be sure to add your plugin to our list of compatible plugins.

    As for cache purging, the only issue we would come across would be if your plugin changes the paths in any way. If our cached page is expecting a certain url and your plugin already changed the url to something else, that’s when we’d have issues.

    If you need anything from us, let us know!

    Cheers,
    Kevin

    I don’t think there will be any issues on FVM end, even If we change paths.

    If the users purge LiteSpeed (partially or full), my plugin will generate new static files as soon as the uncached version is requested on the browser (which will then be used by the full page cache).

    Likewise, purging FVM cache, will trigger a full purge on LiteSpeed, so we know for sure that there won’t be any references left to our “old” files.

    If users do not ever purge FVM cache, the old files will expire after 45 days… so that’s more than enough time to invalidate the cache.
    I’ll look into making this more efficient, rather than just delete old files after 45 days, however, I don’t think there will be a problem.

    Thanks for adding us to the compatible plugins list.
    Your plugin is also on mine too.

    Regards,
    Raul

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to trigger a cache purge from another plugin?’ is closed to new replies.