• Resolved katmacau

    (@katmacau)


    Hello. I have some content that appears based on if a session variable has been set. For example, if they are a repeat viewer (have a session var stored) then a header strip appears. The problem is that hummingbird is caching the pages without the header strip.

    I need it show the header strip if the session variable is set. I know you can do things with cookies and logged in status. but how to I get it to no cache pages if session var set?

    Can I just put this into my header.php in the theme to dynamically set cache status for all pages?

    <?php if(is_user_logged_in() || isset($_SESSION['repeat_viewer']) {
    define('DONOTCACHEPAGE', true); } ?>

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @katmacau

    I hope you are doing good today.

    We do not have any feature yet, which will allow o not to cache specific parts on the page. The only way in those cases will be, for now, to use iframe, which loads content from a different page that is not cached.

    Kind Regards,
    Kris

    Thread Starter katmacau

    (@katmacau)

    Thanks. But it was more I dont want the entire page to be cached when that session var is set. So general public see cached pages, those who are wordpress logged in OR those who have that session variable set I want them to see non-cached pages.

    Is that possible? On an entire page level?

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @katmacau

    For the entire page, your code should work yes.

    I just tested on my lab site by using

    [2022-03-03T14:56:39+00:00] Page not cached because DONOTCACHEPAGE is defined.

    session_start();
    
    $_SESSION["repeat_viewer"]='just a test';
    
    if( isset( $_SESSION['repeat_viewer'] ) ) {
    define('DONOTCACHEPAGE', true); }
    ?>

    And it prevents the cache as expected.

    Just some important notes, by default, Hummingbird won’t cache logged-in users, unless you enable it in Hummingbird settings, if you don’t enable it the code is not necessary.

    On your code is missing an extra )

    <?php if( is_user_logged_in() || isset( $_SESSION['repeat_viewer'] ) ) {
    define('DONOTCACHEPAGE', true); } ?>

    Best Regards
    Patrick Freitas

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @katmacau ,

    We haven’t heard from you for some time now, so it looks like you don’t need our assistance anymore.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

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

The topic ‘Disable caching if session variable exists’ is closed to new replies.