Guest page caching

vikasdangi

Member
I also having the same problem. My php version is 7.4, I also checked the problem in php 7.3, 7.2, 7.1, 7.0.
My hosting provider is runcloud.
 

Masetrix

Well-known member
We have done a few tests in the meantime and attribute the problem to Redis.
First we tested the XFs disk cache where the problem no longer occurred.
We are now using Memcache and there is no longer a problem with PageCache.
 

vikasdangi

Member
We have done a few tests in the meantime and attribute the problem to Redis.
First we tested the XFs disk cache where the problem no longer occurred.
We are now using Memcache and there is no longer a problem with PageCache.
I have tried all three Redis, Memcached and Filesystem cache, and problem occurring in all of them.

Can you provide the full config code used for memcached and disk cache
 

Masetrix

Well-known member
I remember trying that too and the problem still occurred on Memcache too.
Completely without Redis, and only Memcached, there are no more problems here.

Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
    'server' => '127.0.0.1'
];
 

vikasdangi

Member
$config['cache']['enabled'] = true; $config['cache']['provider'] = 'Memcached'; $config['cache']['config'] = [ 'server' => '127.0.0.1' ];
I think this code will not enable guest page caching. I am talking about guest page caching with memcached or filesystem or redis.
 

vikasdangi

Member
Completely without Redis, and only Memcached, there are no more problems here.

Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
    'server' => '127.0.0.1'
];
you need something like this code to enable guest page cache with memcached:

PHP:
$config['cache']['enabled'] = true;
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Memcached';
$config['cache']['context']['page']['config'] = [
        'host' => '127.0.0.1',
        'port' => 6379,
        'database' => 4
        ];
And the problem exists with this code.
 

Masetrix

Well-known member
I have tried all three Redis, Memcached and Filesystem cache, and problem occurring in all of them.

Can you provide the full config code used for memcached and disk cache
Here my old Config for FileSystemCache:
Code:
$config['cache']['enabled'] =  true;
$config['cache']['provider'] = 'Filesystem';
$config['cache']['config'] = ['directory' => '/var/www/vhosts/mydomain.tld/httpdocs/internal_data/xenforo-cache']; // fullpath must exist!
$config['cache']['registry'] = true;
$config['cache']['sessions'] = true;
$config['cache']['css']['enabled'] = true;
// guest page cache
$config['pageCache']['enabled'] = true;
$config['pageCache']['provider'] = 'Filesystem';
$config['pageCache']['config'] = ['directory' => '/var/www/vhosts/mydomain.tld/httpdocs/internal_data/xenforo-cache'];
$config['pageCache']['lifetime'] = 300;
$config['pageCache']['recordSessionActivity'] = true;
 
Last edited:

Masetrix

Well-known member
@all You are right. The problem also occurs when using memcached or XF's hard disk cache.

For me here, however, not when I use Firefox72.0.1 (64-Bit), but only with Chrome( Version 79.0.3945.117). My (test) error Sorry for that.
 
Last edited:

arn

Well-known member
Interesting. I'm going to see if I can recreate this tomorrow if I get a chance on a different server with a base install. If I can hopefully it will aid in one of us getting to the bottom of this for @JoyFreak
I think I figured out this guest cache 304 thing for me at least. I'm using Cloudflare to guest cache my pages. So not using Xenforo's system.

In Chrome/Firefox, when I logout, I get what looks like a Logged in page. As stated, this is because a 304 response from Cloudflare, not from Xenforo. I'm bypassing cache based on the xf_lscxf_logged_in cookie (amongst others)

What's happening:

1. Log in -> xf_lscxf_logged_in cookie set
2. Bypass Cloudflare cache on all pages b/c of xf_lscxf_logged_in cookie
3. Log out -> xf_lscxf_logged_in removed, you are considered a Guest and sent to main forum home
4. Cloudflare thinks you are a normal guest, checks it's cache and it hasn't changed, so it sends you a 304 -- not knowing that your browser's cache is outdated. Browser, shows you logged in, since that is cached locally on your computer.

My quick solution is:

Add a new cache bypass cookie "mr_logged_out" to Cloudflare
Ideally, when logging out, set a "mr_logged_out=1" session cookie
Now when you are sent to the forum home, Cloudflare bypasses its cache and serves a fresh (logged out) page, instead of telling your browser to deliver what it has cached

I've tested it by giving everyone logged in a "mr_logged_out" session cookie (explicitly set a cookie via js for all logged in users in helper_js-global - see code below). So when you logout, you will be bypassing the cache (for the rest of that browser session). Ideally, this cookie would only be set upon logout, but that would require a small add-on.

Anyone test and see if that works for you?

arn

Code:
    <xf:if is="$xf.visitor.user_id">
<script>
    function mr_setCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
}

mr_setCookie("mr_logged_out","1","")

</script>
    </xf:if>
 
Last edited:
Top