• Resolved nando4

    (@nando4)


    I have a ESI block set public, ttl=900. Inspecting it’s page shows LS debug messages as follows following the ESI block.

    <!-- Block cached by LiteSpeed Cache 5.5.1 on 2023-08-07 15:39:25 --> 
    <!-- X-LiteSpeed-Cache-Control: private,no-vary,max-age=3600 --> 
    <!-- X-LiteSpeed-Tag: 3a6_tag_priv,public:3a6_HTTP.200,public:3a6_ESI,public:3a6_ESI.widget,public:3a6_ -->

    This page in the “Force Cache URIs” list.

    How have I been able to purge the ESI block?

    • LS WP Admin panel
    • At CLI: ‘wp litespeed-purge’
    • let the TTL expire.

    These more convenient methods where I’m not purging the whole website don’t work

    • LS WP Admin panel -> Purge Page
    • wp litespeed-purge post_id [post_id]
    • wp litespeed-purge url [url]
    • wp litespeed-purge tag [tag] -> expects a numeric tag

    Am hopeful to get some guidance here to be able to selectively purge the ESI block and/or containing page. Thank you.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support qtwrk

    (@qtwrk)

    please try create a php file with code

    <?php
    require( './wp-load.php' );
    do_action( 'litespeed_purge', 'ESI.widget' );

    and access it , see if it works

    Thread Starter nando4

    (@nando4)

    Thank you, can confirm that above code purges my ESI block so the next access to the page runs a new instance of it. Though it raises two points:

    1. How can I designate a more appropriate tag I can work with rather than the ESI shortcode assigns? , eg: tag the ESI block with the post-ID the ESI block lives on? Is there filter code that can be added to functions.php so ALL ESI shortcodes do that?
    2. For my testing/prototyping ESI, it seems a critical oversight in the WP LS cache dashboard, admin bar and CLI interface to not have a mechanism to clear ESI blocks requiring the above code or Purge All to do so. Can an enhancement request be added for this, eg: purge page including ESI blocks.

    I only by accident discovered that altering the widget’s ESI block parameters and saving the widget ensures that ESI blocked widget gets purged and re-run on the page it lives on.

    • This reply was modified 1 year, 6 months ago by nando4.
    • This reply was modified 1 year, 6 months ago by nando4.
    • This reply was modified 1 year, 6 months ago by nando4.
    Plugin Support qtwrk

    (@qtwrk)

    for 1), imagine you have shortcode like

    [my_shortcode]

    then you can add this to functions.php

    add_action('litespeed_esi_shortcode-my_shortcode, function() {
        do_action('litespeed_tag_add', 'my_custom_tag');
    });

    for 2) , yeah … I sort of noticed that and forces me to use code instead of GUI to purge tag , will ask our devs to think something about it

    Thread Starter nando4

    (@nando4)

    Have had no luck adding your suggested code, copied below with my shortcode name, to my functions.php to allow me to change the tag of the ESI block.

    add_action('litespeed_esi_shortcode-my_echo', function() {
    do_action('litespeed_tag_add', get_the_ID());
    });

    Maybe you can double-check what I am doing to confirm it’s correct?

    1. add a my_echo shortcode to my functions.php:

    add_shortcode('my_echo', 'my_echo_shortcode');
    function my_echo_shortcode($params) {
    echo ' . implode(' ', $params) . '';
    }

    2. add an ESI prefix to call my shortcode on my page:shortcode:

    [ESI my_echo "hello there" ttl="9999999"]

    The LS debugged output after the shortcode output shows the tags associated with the ESI block. The postID is not in there.

    <div style="background: blue; color: white; text-align: center;">hello there</div> 
    <!-- Block cached by LiteSpeed Cache 5.5.1 on 2023-08-09 10:46:12 --> 
    <!-- X-LiteSpeed-Cache-Control: public,no-vary,max-age=99999 --> 
    <!-- X-LiteSpeed-Tag: 3a6_HTTP.200,3a6_ESI,3a6_ESI.esi,3a6_ESI.esi.my_echo,3a6_ -->

    I did manage to get the tagged ESI block by adding my_echo_shortcode:

    function my_echo_shortcode($params) {
    echo '' . implode(' ', $params) . '';
    do_action('litespeed_add_tag', get_the_id());
    }

    The LS debugged output shows the postID in the X-LiteSpeed-Tag correctly below:

    <div style="background: blue; color: white; text-align: center;">hello there</div> 
    <!-- Block cached by LiteSpeed Cache 5.5.1 on 2023-08-09 11:08:03 --> 
    <!-- X-LiteSpeed-Cache-Control: public,no-vary,max-age=99999 --> 
    <!-- X-LiteSpeed-Tag: 3a6_HTTP.200,3a6_ESI,3a6_ESI.esi,3a6_ESI.esi.my_echo,3a6_33565,3a6_ -->

    Which now begs the question:

    how can I tag a ESI shortcode that calls other author’s shortcodes rather than my own where I’ve added do_action('litespeed_add_tag', get_the_id());‘?

    Thread Starter nando4

    (@nando4)

    Or maybe you can ask the devs fix these issue with ESI shortcode tagging ESI blocks and being able to purge them. Ie:

    • update the ESI shortcode to add postID of post/page it is in into the ESI block tag
    • fix LS WP Admin panel -> Purge Page to purge ESI blocks with same post ID in it?
    • fix ‘wp litespeed-purge post_id [post_id]’ CLI interface to do the same
    • fix ‘wp litespeed-purge url [url]’ CLI to do the same
    • fix ‘wp litespeed-purge tag [tag]’ CLI to allow purge of a ESI tag
    Plugin Support qtwrk

    (@qtwrk)

    ref: https://github.com/litespeedtech/lscache_wp/blob/54d44932d0c420122cdc57759764474e76d7a74f/src/esi.cls.php#L217

    the do_action here is

    'litespeed_esi_shortcode-' . $atts[ 0 ] 

    so that $atts[0] should be the shortcode name from other plugins

    I will forward it.

    Thread Starter nando4

    (@nando4)

    Appreciate your good work in confirming my observations. Will keep an eye out for a LS plugin update.

    Thread Starter nando4

    (@nando4)

    With regards to purging the ESI block, your code you supplied earlier worked when I created an exec widget in WP, place it on a test page, then opened that page using a browser:

    <?php
    require( './wp-load.php' );
    do_action( 'litespeed_purge', 'ESI.widget' );

    However, when I create this as a php file on the server, and run it as su or user under which WP runs “php file.php”, it doesn’t purge the block. This may also explain why ‘wp litespeed-purge tag [tag]’ doesn’t work either.

    Can you confirm this works on your environment when run using php at a server prompt?

    Plugin Support qtwrk

    (@qtwrk)

    due to the way how LSCache works , as it is integrated into webserver, command line won’t work nicely , it will be delayed until next time PHP is triggered by webserver , for instant purge, you need to run it like

    curl -I -XGET https://yourdomain.com/your_file.php
    • This reply was modified 1 year, 6 months ago by qtwrk.
    Thread Starter nando4

    (@nando4)

    Confirm that method works. Thank you.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to purge ESI blocks on a page without purging whole site cache?’ is closed to new replies.