Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable cache for logged in users #22

Open
roryashfordbentley opened this issue Jul 18, 2022 · 2 comments
Open

Enable cache for logged in users #22

roryashfordbentley opened this issue Jul 18, 2022 · 2 comments

Comments

@roryashfordbentley
Copy link

Hey, first of all thanks for the excellent plugin, it works incredibly well out of the box!

I have been poking through the plugin source code and I can't seem to find the logic that disables/prevents caching for logged in users.

What I am hoping is possible is that I can create a custom config file like this Surge Configuration Example. And setup some logic to enable caching for logged in users with a certain custom role (essentially a role that only has frontend access).

If you could point me in the direction of how Surge currently identifies logged in users I'd really appreciate it.

@doiftrue
Copy link
Contributor

doiftrue commented Jul 19, 2022

WP use wp_get_nocache_headers() to set no-cache headers for logged in users.

It seams, You can modify this header to control cashing in Surge. Example: somewhere in the theme's functions.php:

add_action( 'wp', function(){
    
    if( is_user_logged_in() ){
        header_remove( 'Cache-Control' );
    }
} );

@MadtownLems
Copy link

I tried using the header_remove() code snippet above, and it wasn't working properly for me. I tried nocache_headers() instead, and that seems to be working.

https://developer.wordpress.org/reference/functions/nocache_headers/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants