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?