• Resolved rudolfl

    (@rudolfl)


    Hi

    I have custom shortcode that outputs some data dynamically based on certain conditions. I just realised this is being cached.

    In my case data is displayed based on the current date. “Product will be available after 26 May 2025”. Today I realised message was still displaying. I cleared LS Cache for the page and message disappeared as it should.

    So, is there a way to exclude this data blob from caching?

    Thanks

    Rudolf

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

    (@qtwrk)

    ESI shortcode ?

    if ESI is not option , then you need to find a hook or something that fires when the date reaches to purge the cache

    Thread Starter rudolfl

    (@rudolfl)

    Hi

    I am not familiar with ESI shortcode, so should do some study there. Shortcode is written by me, so can change, just need to figure out what to do. Please do share any examples/docs you may have.

    Another option I am thinking of is to output this data via Ajax. “admin_ajax.php” is already excluded from caching/optimisation. But Ajax is a bit messier to implement

    Rudolf

    Plugin Support qtwrk

    (@qtwrk)

    okay , ajax is good way to go

    here is an example esi shortcode plugin I created before , create a file like wp-content/plugins/current-time/current-time.php with code:

    <?php
    /*
    Plugin Name: Current time plugin
    Description: Current time plugin
    */

    defined('WPINC') || exit;

    function check_lscwp_esi_status() {
    if (!defined('LSCWP_V') || !apply_filters('litespeed_esi_status', false)) {
    return;
    } else {
    add_action('litespeed_esi_load-current_time_esi_block', 'current_time_esi_block_esi_load');
    }
    }
    add_action('init', 'check_lscwp_esi_status', 999);


    function current_time_esi_block_esi_load() {
    do_action('litespeed_control_set_nocache');
    echo 'Time: ' . date('Y-m-d H:i:s');
    }

    function lscwp_esi_display_time_shortcode() {
    return apply_filters('litespeed_esi_url', 'current_time_esi_block', 'Current time display ESI block');
    }

    function register_current_time_shortcode() {
    add_shortcode('current_time', 'lscwp_esi_display_time_shortcode');
    }
    add_action('init', 'register_current_time_shortcode');



    function display_current_time_noesi() {
    return date('Y-m-d H:i:s');
    }

    function register_current_time_shortcode_noesi() {
    add_shortcode('current_time_noesi', 'display_current_time_noesi');
    }
    add_action('init', 'register_current_time_shortcode_noesi');

    then activate plugin , enable ESI in LiteSpeed plugin , add shortcode

    [current_time] in a post , you will see page still cache hit while current time is reflecting in real time

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Caching of dynamic data’ is closed to new replies.