• Resolved Ari123

    (@ucdguy)


    Hi,

    Thank you for a great plugin!

    What do I need help with?

    I want all logged in users to be served the public cache, rather than private cache or not being cached.

    Why do I want this?

    On my particular website, 99% of the pages is the same for logged in and logged out users. The remaining 1% of the pages is being excluded from cache. Therefore, there is no purpose to having a separate public and private cache as they will be the exact same. (I also don’t have a separate header for logged in and logged out users etc.).

    What have I tried?

    I’ve tried all three of the following, but none seem to work.

    function custom_litespeed_cache_control($cache_control) {
    if ( current_user_can('administrator') ) {
    // Disable cache for administrators
    $cache_control->disable_cache();
    } else {
    // Serve public cache to all other logged-in users
    $cache_control->enable_cache();
    $cache_control->add_cacheable_role('subscriber');
    // Add more roles if needed
    }
    }

    add_action('litespeed_control_set', 'custom_litespeed_cache_control');
    function custom_litespeed_cache_control($cache_control) {
    if ( current_user_can('administrator') ) {
    // Disable cache for administrators
    $cache_control->disable_cache();
    } else {
    // Enable cache for all other logged-in users
    $cache_control->set_public();
    }
    }

    add_action('litespeed_control_set', 'custom_litespeed_cache_control');
    function custom_litespeed_cache_control($cache_control) {
    if ( current_user_can('administrator') ) {
    // Disable cache for administrators
    $cache_control->disable_cache();
    } else {
    // Set the cache to public for all other logged-in users
    $cache_control->set_public();
    }
    }

    add_action('litespeed_control_set', 'custom_litespeed_cache_control');

    function lscache_public_for_logged_in_users() {
    if ( !current_user_can('administrator') && is_user_logged_in() ) {
    define('LSCACHE_IS_FORCED', true);
    define('LSCACHE_IS_ESI', true);
    }
    }

    add_action('init', 'lscache_public_for_logged_in_users');

    Any advice? Thank you for your help! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support litetim

    (@litetim)

    Hello
    1) By default pages are not cached when user is logged in
    2) action litespeed_control_set does not exists in current version. Also LSCACHE_IS_ESI is used to identify a selected feature in plugin.
    3) the site is exactly the same for logged in and logged out user? don’t you have admin bar that appears?
    4) Try this setting: LSC -> CACHE -> Cache(from top inner menu) -> Force Public Cache URIs

    Thread Starter Ari123

    (@ucdguy)

    “the site is exactly the same for logged in and logged out user? don’t you have admin bar that appears?”

    Yes , which is why I why disabling cache for admins in the functions above.

    if ( current_user_can('administrator') ) {
    // Disable cache for administrators
    $cache_control->disable_cache();
    }

    Try this setting: LSC -> CACHE -> Cache(from top inner menu) -> Force Public Cache URIs

    According to qtwrk in this thread, that setting still honors the login status.

    Is there no basic function to push the public cache to logged in users? Has litespeed_control_set been replaced by something that makes this still possible?

    Thank you for your help! 🙂

    Plugin Support qtwrk

    (@qtwrk)

    unfortunately the plugin doesn’t really work that way , it wasn’t designed to be act like that.

    Plugin Support litetim

    (@litetim)

    Try these hooks:

    do_action( 'litespeed_control_force_cacheable', 'if it be not to come, it will be now' );

    do_action( 'litespeed_control_set_private', 'Listen to many, speak to a few.' );

    do_action( 'litespeed_control_force_public', 'Brevity is the soul of wit.' );

    Also there is this vary filter:
    apply_filters('litespeed_vary', $vary)
    that need to clear key: $vary[‘logged-in‘] for logged in user

    Hope will help 🙂

    • This reply was modified 1 year, 8 months ago by litetim.
    • This reply was modified 1 year, 8 months ago by litetim.
    • This reply was modified 1 year, 8 months ago by litetim.
    Thread Starter Ari123

    (@ucdguy)

    That seems to have helped, thank you. 🙂

    Plugin Support litetim

    (@litetim)

    Which part? 🙂

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

The topic ‘Serving the public cache to logged in users’ is closed to new replies.