• Resolved nookyyy

    (@nookyyy)


    Hi,

    i would like to have no ttl on a custom esi block (or a really high one) and trigger a purge when i create a new post / update a post and thus the order of the posts (order by custom numeric field (rating)) changes.

    How can i target the esi block and purge it – i tried everything and cant get it to work ??

    thanks for your help

    regards

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter nookyyy

    (@nookyyy)

    This is one block for example i want to purge:

    <!-- Block cached by LiteSpeed Cache 6.5.2 on 2024-11-08 14:16:36 -->
    <!-- X-LiteSpeed-Cache-Control: public,max-age=120,esi=on -->
    <!-- X-LiteSpeed-Tag: b79_HTTP.200,b79_ESI,b79_ESI.custom-block-template-4002,b79_W.bricks-template-4002,b79_ -->

    which i create here:

    function custom_block_esi_load($params) {

    do_action( 'litespeed_control_set_ttl', 120 );
    do_action( 'litespeed_tag_add_widget', 'bricks-template-' . $params['template_id'] );

    //block content
    }

    and here is the filter for the esi_url

    echo apply_filters('litespeed_esi_url', 'custom-block-template-' . $template_id, 'ESI Block ' . $template_id, array('template_id' => $template_id, 'post_id' => $post_id), 'public', false, false, true, false);

    I’ve tested the actions described here (https://docs.litespeedtech.com/lscache/lscwp/api/#purge-a-cache-tag) but nothing works – the automatic purge of a page by id works ( when theres a new product for example i have to purge two sites but on the others like frontpage i only need to purge the esi block )

    Plugin Support qtwrk

    (@qtwrk)

    do_action( 'litespeed_purge', 'ESI' );

    have you tried this ?

    Thread Starter nookyyy

    (@nookyyy)

    Just did – same thing nothing happens.

    I’ve tested litespeed_add_tag aswell and then purge it with several actions:

    if ( is_plugin_active( 'litespeed-cache/litespeed-cache.php' ) ) {
    $debug_string = '';
    foreach ($esi_blocks_to_purge as $block) {
    $debug_string .= 'PURGE: ' . $block . "\n";
    do_action('litespeed_purge', $block);
    do_action('litespeed_purge_esi', $block);
    do_action('litespeed_purge_widget', $block);

    }

    do_action( 'litespeed_purge', 'ESI' );

    foreach ($esi_page_to_purge as $page) {
    $debug_string .= 'PURGE: ' . $page . "\n";
    do_action( 'litespeed_purge_post', $page );

    }


    if (!empty($debug_string)) {
    update_field('product_debug', $debug_string, $post_id);
    }
    }

    and the block names are here for example:

    $esi_blocks_to_purge[] = 'template-4002'; // Best Mouse — DE
    $esi_blocks_to_purge[] = 'template-4698'; // Best Mouse — EN
    $esi_blocks_to_purge[] = 'bricks-template-4002'; // Best Mouse — DE
    $esi_blocks_to_purge[] = 'bricks-template-4698'; // Best Mouse — EN

    and the purge log:

    with purge_esi / purge_widget / purge + the blocks in the array

    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] ?? ------POST HTTP/1.1 (HTTPS) /wp-admin/post.php
    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] Query String:
    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] HTTP_REFERER: https://nookyyy.com/wp-admin/post.php?post=3197&actio...
    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit...
    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] Accept Encoding: br,gzip
    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] Cookie _lscache_vary: admin_bar:1;guest_mode:1;logged-in:1;role:99
    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] X-LSCACHE: true
    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] LSCACHE_VARY_VALUE: +webp
    11/08/24 16:00:30.170 [80.139.162.165:58500 1 SVJ] X-LiteSpeed-Purge: public,stale,b79_Po.3197,b79_URL./reviews/mouse/vgn/dragonfly-f1-pro-max/,b79_W.recent-posts-1,b79_FD,b79_REST,b79_template-4002,b79_ESI.template-4002,b79_template-4698,b79_ESI.template-4698,b79_bricks-template-4002,b79_ESI.bricks-template-4002,b79_bricks-template-4698,b79_ESI.bricks-template-4698,b79_Po.4050,b79_URL./reviews/mouse/,b79_Po.4708,b79_URL./en/reviews/mouse/ => LiteSpeed\LSC->send_headers()@624 => WP_Hook->apply_filters(,ARRAY)@324 => WP_Hook->do_action(ARRAY)@348 =>
    /var/www/vhosts/nookyyy.com/httpdocs/wp-includes/load.php@517

    with purge 'ESI'

    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] ?? ------POST HTTP/1.1 (HTTPS) /wp-admin/post.php
    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] Query String:
    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] HTTP_REFERER: https://nookyyy.com/wp-admin/post.php?post=3197&actio...
    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit...
    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] Accept Encoding: br,gzip
    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] Cookie _lscache_vary: admin_bar:1;guest_mode:1;logged-in:1;role:99
    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] X-LSCACHE: true
    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] LSCACHE_VARY_VALUE: +webp
    11/08/24 16:04:05.073 [80.139.162.165:39396 1 O2m] X-LiteSpeed-Purge: public,stale,b79_Po.3197,b79_URL./reviews/mouse/vgn/dragonfly-f1-pro-max/,b79_W.recent-posts-1,b79_FD,b79_REST,b79_ESI,b79_Po.4050,b79_URL./reviews/mouse/,b79_Po.4708,b79_URL./en/reviews/mouse/ => LiteSpeed\LSC->send_headers()@624 => WP_Hook->apply_filters(,ARRAY)@324 => WP_Hook->do_action(ARRAY)@348 =>
    /var/www/vhosts/nookyyy.com/httpdocs/wp-includes/load.php@517
    Plugin Support qtwrk

    (@qtwrk)

    if you simply do

    <?php
    require( './wp-load.php' );
    if ( defined('LSCWP_V')) {
    do_action( 'litespeed_purge', 'ESI' );

    }

    as standalone , did it purge esi ?

    Thread Starter nookyyy

    (@nookyyy)

    created a file esi.php in root with your code ->

    11/08/24 18:24:23.361 [80.139.162.165:40364 1 5Vh] ?? ——GET HTTP/1.1 (HTTPS) /esi.php
    11/08/24 18:24:23.361 [80.139.162.165:40364 1 5Vh] Query String:
    11/08/24 18:24:23.361 [80.139.162.165:40364 1 5Vh] User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit…
    11/08/24 18:24:23.361 [80.139.162.165:40364 1 5Vh] Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
    11/08/24 18:24:23.361 [80.139.162.165:40364 1 5Vh] Accept Encoding: br,gzip
    11/08/24 18:24:23.361 [80.139.162.165:40364 1 5Vh] Cookie _lscache_vary: admin_bar:1;guest_mode:1;logged-in:1;role:99
    11/08/24 18:24:23.361 [80.139.162.165:40364 1 5Vh] X-LSCACHE: true
    11/08/24 18:24:23.361 [80.139.162.165:40364 1 5Vh] LSCACHE_VARY_VALUE: +webp
    11/08/24 18:24:23.361 [80.139.162.165:40364 1 5Vh] X-LiteSpeed-Purge: public,stale,b79_ESI => LiteSpeed\LSC->send_headers()@624 => WP_Hook->apply_filters(,ARRAY)@324 => WP_Hook->do_action(ARRAY)@348 =>
    /var/www/vhosts/nookyyy.com/httpdocs/wp-includes/load.php@517

    still the same after i open https://nookyyy.com/esi.php – no esi purge triggered

    Thread Starter nookyyy

    (@nookyyy)

    Ok i think i finally found a way – but im not sure if this is how it should work ( feels like some actions are not working or not clearly described in the docs ? )

    Whats working now:

    // in apply_filters i had to add 'public,no-vary' ( i only had public before ) :

    echo apply_filters('litespeed_esi_url', 'custom-block-template-' . $template_id, 'ESI Block ' . $template_id, array('template_id' => $template_id, 'post_id' => $post_id), 'public,no-vary', false, false, true, false);


    //in the custom_block_esi_load func:

    do_action( 'litespeed_tag_add', 'bricks-template-' . $params['template_id'] );

    $esi_blocks_to_purge[] = 'bricks-template-4002'; // Best Mouse — DE
    $esi_blocks_to_purge[] = 'bricks-template-4698'; // Best Mouse — EN

    foreach ($esi_blocks_to_purge as $block) {
    do_action('litespeed_purge', $block);
    }

    do_action( ‘litespeed_purge’, ‘ESI’ ); works now aswell – so i guess the no-vary has something to do with this ?

    And if i dont want to use a custom tag i would have to target the block:

    <!-- X-LiteSpeed-Tag: b79_HTTP.200,b79_ESI,b79_ESI.custom-block-template-4002,b79_bricks-template-4002,b79_ -->

    with do_action(‘litespeed_purge’, ‘ESI.custom-block-template-4002’); and not do_action(‘litespeed_purge’, ‘template-4002’); or do_action(‘litespeed_purge_widget’, ‘template-4002’);
    this was my mistake

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.