Serving the public cache to logged in users
-
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! 🙂
The topic ‘Serving the public cache to logged in users’ is closed to new replies.