Forum Replies Created

Viewing 15 replies - 46 through 60 (of 98 total)
  • Thread Starter Jacob Hill

    (@tekfused)

    Hi @stanleylitespeed, yes, it shows for logged in users, and for users who have not logged in. I submitted a ticket with the information you requested.

    • This reply was modified 6 years, 6 months ago by Jacob Hill.
    Thread Starter Jacob Hill

    (@tekfused)

    Hello @qtwrk, thanks for the response. I have tried, and the value still reverts back as I described in my original post. I’m using the latest version, 2.9.8.7. I went ahead and generated another report if that helps: HVVHRNUB.

    • This reply was modified 6 years, 6 months ago by Jacob Hill.
    Thread Starter Jacob Hill

    (@tekfused)

    Hi @stanleylitespeed,

    Thanks for that. I did try this, but when I set the tag to private, it won’t clear the ESI block. I believe there is another issue here – take a look at this excerpt from the code in my previous post:

    <!-- X-LiteSpeed-Tag: 161_tag_priv,public:161_ESI,public:161_ESI.subscription_check_esi,public:161_subscription_check_676,public:161_ -->

    You’ll see public:161_ESI.subscription_check_esi which is actually the ESI block (Not the tag), which should be private, but it is listed as public.

    Again, here is the ESI declaration:

    function esi_subscription_check()
    {
        echo LiteSpeed_Cache_API::esi_url( 'subscription_check_esi', 'Subscription Check ESI', array(), 'private,no-vary' ) ;
    }

    It appears that the ESI block is acting like a private block, in that it is regenerated and maintained separately for each user, but I’m not sure why it is being shown as public in the HTML debug output above.

    Thanks in advance!

    Jake

    Thread Starter Jacob Hill

    (@tekfused)

    Hi @qtwrk, hi @stanleylitespeed, is there an estimate on the release date for 3.0? There are a few fixes like this that I’m really looking forward to. Thanks in advance!

    • This reply was modified 6 years, 7 months ago by Jacob Hill.
    Thread Starter Jacob Hill

    (@tekfused)

    Thanks, @stanleylitespeed! I tried adding ‘no-vary’, but that didn’t fix the issue. I actually had to change the purge action in the do_stuff() function to LiteSpeed_Cache_API::purge( 'subscription_check_' . $user_ID ) ;

    It is odd because I’m declaring it as a private block, yet the private_purge action doesn’t work. I have debug mode enabled, and here is the output at the top of the page’s HTML:

    <!-- Block generated by LiteSpeed Cache 2.9.8.7 on 2019-10-15 21:20:59 -->
    <!-- X-LiteSpeed-Cache-Control: private,no-vary,max-age=86400 -->
    <!-- X-LiteSpeed-Tag: 161_tag_priv,public:161_ESI,public:161_ESI.subscription_check_esi,public:161_subscription_check_676,public:161_ -->
    <!-- Object Cache  [total] 5229 [hit_incall] 5036 [hit] 93 [miss_incall] 30 [miss] 70 [set] 108 -->

    As you can see, it appears that Litespeed is creating the ESI block as a public block opposed to a private block. Not sure why? It appears to function in my testing as a private block, even though the private_purge action doesn’t work.

    Here is the updated code:

    // Initializes the ESI block.
    add_action( 'wp_head', 'esi_subscription_check' );
    function esi_subscription_check()
    {
        echo LiteSpeed_Cache_API::esi_url( 'subscription_check_esi', 'Subscription Check ESI', array(), 'private,no-vary' ) ;
    }
    
    // Enables the ESI block and hooks to a function.
    LiteSpeed_Cache_API::hook_tpl_esi('subscription_check_esi', 'subscription_check_esi_function' ) ;
    function subscription_check_esi_function( $param )
    {
        // Sets the TTL for this ESI block.
        LiteSpeed_Cache_API::set_ttl( 86400 ) ;
        
        // Tags the ESI cache with the current user's ID so the entire user cache doesn't need to be changed later.
        $user_id = get_current_user_id();
        LiteSpeed_Cache_API::tag_add( 'subscription_check_' . $user_id ) ;
        ...
        do_stuff();
    }
    
    function do_stuff()
    {
        ...
        $user_id = ...
        LiteSpeed_Cache_API::purge( 'subscription_check_' . $user_ID ) ;
    }

    Thoughts?

    Thread Starter Jacob Hill

    (@tekfused)

    Hello, @stanleylitespeed! I’m getting back to this, and want to make sure I’m purging the block correctly. I’ve been testing this out, and in my tests, I’ve noticed that if I expire the block using a very short TTL (10 seconds for example), it recalculates instantly after it expires, but when I purge it via the tag, it doesn’t purge instantly (I have to wait 30 seconds before refreshing the page, otherwise I receive the stale block with the JS redirect).

    Here is the code:

    // Initializes the ESI block.
    add_action( 'wp_head', 'esi_subscription_check' );
    function esi_subscription_check()
    {
        echo LiteSpeed_Cache_API::esi_url( 'subscription_check_esi', 'Subscription Check ESI', array(), 'private' ) ;
    }
    
    // Enables the ESI block and hooks to a function.
    LiteSpeed_Cache_API::hook_tpl_esi('subscription_check_esi', 'subscription_check_esi_function' ) ;
    function subscription_check_esi_function( $param )
    {
        // Sets the TTL for this ESI block.
        LiteSpeed_Cache_API::set_ttl( 86400 ) ;
        
        // Tags the ESI cache with the current user's ID so the entire user cache doesn't need to be changed later.
        $user_id = get_current_user_id();
        LiteSpeed_Cache_API::tag_add( 'subscription_check_' . $user_id ) ;
        ...
        do_stuff();
    }
    
    function do_stuff()
    {
        $user_id = ...
        LiteSpeed_Cache_API::purge_private( 'subscription_check_' . $user_ID ) ;
    }

    In the do_stuff() function, am I using the currect tag identifier? Should it be 'esi.subscription_check_' . $user_ID?

    Thanks in advance!

    Jake

    • This reply was modified 6 years, 7 months ago by Jacob Hill.
    • This reply was modified 6 years, 7 months ago by Jacob Hill.
    • This reply was modified 6 years, 7 months ago by Jacob Hill.
    Thread Starter Jacob Hill

    (@tekfused)

    Hi @stanleylitespeed, that is perfect, thank you very much! In this case, I’ll use a tag similar to “${user_email}.${esitag}” and then clear it by using that tag as needed.

    Thread Starter Jacob Hill

    (@tekfused)

    Hi @stanleylitespeed, when I change the hook from wp_head to init, this text appears at the top of the page: [an error occurred while processing this directive]

    As I mentioned, I tried a few other hooks, and wp_head is the only one that worked.

    Thread Starter Jacob Hill

    (@tekfused)

    Hi @stanleylitespeed, thank you very much for getting back with me! I went with option 2, echoing a JS redirect.

    My last question here is why doesn’t the “init” and other hooks work? The only hook that I could get to work was “wp_head.”

    • This reply was modified 6 years, 7 months ago by Jacob Hill.
    Thread Starter Jacob Hill

    (@tekfused)

    Hello @stanleylitespeed, thanks. I assume that would clear the private cache for all users. Is there any way to pass a user ID (Or another identifier) to this so that it clears the private cache for a specific user?

    • This reply was modified 6 years, 7 months ago by Jacob Hill.
    • This reply was modified 6 years, 7 months ago by Jacob Hill.
    Thread Starter Jacob Hill

    (@tekfused)

    Quick update: it seems that using the init, wp_loaded, and wp hooks do not work. I’ve only had success with the wp_head hook. wp_redirect() does not work though.

    Here is a simplified snippet:

    add_action( 'wp_head', 'esi_time' );
    function esi_time()
    {
        echo LiteSpeed_Cache_API::esi_url( 'show_your_time', 'xxx Name' ) ;
    }
    
    LiteSpeed_Cache_API::hook_tpl_esi('show_your_time', 'show_your_time' ) ;
    function show_your_time( $param )
    {
        LiteSpeed_Cache_API::set_ttl( 15 ) ;
        
        $user_ID = get_current_user_id();
        $wp_user_obj = new WP_User( $user_ID );
        
        $current_user = wp_get_current_user();
        $wp_user_obj->set_role( 'subscriber' );
        echo date("h:i:sa") ;
    }

    Any idea why the other hooks won’t work?

    • This reply was modified 6 years, 8 months ago by Jacob Hill.
    Thread Starter Jacob Hill

    (@tekfused)

    Hi @stanleylitespeed, then if I echo something in addition to the code I’m processing, it should work?

    Yes, it does need to be server side, because the user’s role may need to be updated, as well as potential calls to a 3rd party API.

    Thread Starter Jacob Hill

    (@tekfused)

    Hi @stanleylitespeed!

    FYI, I’ve generated a LS Cache report for you – HTWNZAJH.

    Thanks for the quick reply. In this case, I’m not trying to print/echo anything on the screen, I just want to use ESI to run some PHP which will check to see if the user has an active WooCommerce Subscription, and then redirect to a “Renew Your Membership” page if their subscription has expired.

    The write_log function in the snippet is another function that writes to the debug.log file. It seems LiteSpeed_Cache_API::hook_tpl_esi never calls the subscription_check() function, because I don’t see any new adds to the debug.log file.

    And yes, I use my child theme’s function.php file.

    I forgot to include that I do have the set_ttl command as well:

    add_action( 'init', 'esi_subscription_check' );
    function esi_subscription_check()
    {
        return LiteSpeed_Cache_API::esi_url( 'subscription_check_esi', 'Subscription Check' );
    }
    
    LiteSpeed_Cache_API::hook_tpl_esi('subscription_check_esi', 'subscription_check' ) ;
    
    function subscription_check()
    {
    	LiteSpeed_Cache_API::set_ttl( 15 ) ;
    	$current_user = wp_get_current_user();
    	write_log($current_user->user_email. ' | Page: ' . get_the_title() . ' | UserTime is '.time());
    	// Do stuff here.
    }

    Thanks again for the help!

    Jacob Hill

    • This reply was modified 6 years, 8 months ago by Jacob Hill.
    Thread Starter Jacob Hill

    (@tekfused)

    Hello @rafasshop,

    I created a thread regarding the vary group bug you mentioned, and they said that it would be fixed in v3.0: https://wordpress.org/support/topic/cant-assign-vary-group-to-more-than-one-role/

    I haven’t experimented much with the TTL settings yet, so I can’t help there. Sorry about that.

    Have a great week!

    Jake

    Thread Starter Jacob Hill

    (@tekfused)

    Hello!

    Just checking to see when 3.0 is expected to drop. I’m excited to see this and other fixes! Thanks!

    Jake

Viewing 15 replies - 46 through 60 (of 98 total)