XF 2.1 Guest page caching

JoyFreak

Well-known member
So I have this in my config already:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
'host' => '127.0.0.1',
'password' => 'Boobs!'
];


Do I just need to simply add this in the end?
$config['pageCache']['enabled'] = true;
 
I didn't know that I could use this provider there as well, thank you very much @Nuno.

Just be aware of this Mike's comment about sharing the same cache instance:

 
Because it does not have to do any PHP processing to deliver a cached page whereas the inbuilt solution does require XF to bootstrap.
But you loose flexibility/features with LiteSpeedCache like not updating sessions, etc.
 
You don't have to separate them, but if you don't, it's important you understand the potential effects if the page cache grows larger than you expect.

For example, let's assume you use the same Memcached instance for sessions and other data, on top of the guest cache data. If you have a lot of active guests, this could create a lot of data, particularly if you choose a longer lifetime. If Memcached fills up, it will start dropping the least recently used (LRU) entries. This could be user sessions. This could lead to users being logged out or them not being able to complete actions (including registering).

Because guest caching can create a lot of data and can be unpredictable in terms of size, we recommend using a separate instance so that guest cache data doesn't push out sessions or other more significant data. The approach of the "page" cache context is to prevent you from accidentally creating the situation I described. If you understand what's going on and can monitor your cache to ensure that doesn't happen (or doesn't happen regularly), then you can use the same instance.

In terms of Memcached, you can run different instances on different ports. Some installations may even support this out of the box with the service code: https://stackoverflow.com/questions...-memcached-server-in-same-server-in-different
I think I have it configured correctly for redis caching on 2 instances of redis servers on port 6479 and 6480

In below config where does $config['cache']['sessions'] = true; setting put the cached sessions ? looks like within the global cache instance ?

PHP:
// https://xenforo.com/xf2-docs/manual/cache/
// global cache
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6480,
    'serializer' => 'igbinary',
//  'password' => 'password',
    'timeout' => 0.0,
    'database' => 3,
    'persistent' => true
];

// session cache
$config['cache']['sessions'] = true;

// guest page cache
$config['pageCache']['enabled'] = true;
$config['pageCache']['lifetime'] = 900;
$config['pageCache']['recordSessionActivity'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6479,
    'serializer' => 'igbinary',
    'database' => 5,
    'timeout' => 1,
    'persistent' => true
];

// css cache
// $config['css']['enabled'] = true;
$config['cache']['context']['css']['provider'] = 'Redis';
$config['cache']['context']['css']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6480,
    'serializer' => 'igbinary',
    'database' => 7,
    'timeout' => 1,
    'persistent' => true
];

194858
194859194860
 
LiteSpeed Cache will definitly be faster.
Yup, LiteSpeed cache would be faster as would nginx php-fpm fastcgi_cache or varnish cache as all these totally bypass any PHP processing unlike Xenforo 2.1 native cache it still needs to go through PHP itself.

Would be great if Xenforo 2.1 advanced caching could manage special cookies as outlined/suggested at https://xenforo.com/community/threa...e-caching-and-more.155203/page-4#post-1290848:)

Would advanced cache configurations have any option to just offload guest caching logic to the web server itself ?

For example, when guest caching is enabled add a special cookie to distinctly detect guest vs logged in and/or maybe even tag specific routes with specific cookies which we can programatically configure at web server level to include or exclude from caching ?

i.e. for nginx PHP-FPM fastcgi_cache https://xenforo.com/community/resou...x-fastcgi_cache-full-page-guest-caching.5393/ and similarly for Nginx proxy_cache you can set cache to include or exclude requests based on detected cookies.

The same can be done for other cache accelerators like Varnish Cache and LiteSpeed Cache Addon for utilising a special cookie(s) to determine what can/cannot be cached. So such an optional advanced option would be useful for folks wanting XF 2.1 to offload full page guest caching from PHP to the upstream web server or web accelerator itself :)

Such a cookie(s) feature would also work with Cloudflare Business level plans and higher for bypass cache on cookie page rules outlined at https://blog.cloudflare.com/caching-anonymous-page-views/ so you can offload full page guest caching to Cloudflare too! So larger Xenforo clients who don't want to mess with web server level cache configurations can just use Cloudflare Business level plans to configure page rules for bypass cache on cookie settings and enable XF 2.1 advanced cache cookie(s) route setups. Cloudflare Enterprise plans can even go one better with Cloudflare Custom Cache Keys to cache on cookie detection.

By adding advanced XF 2.1 full page guest caching routes by cookie(s) you will single handily allow alot of upstream PHP offloading methods for much better performance via

  • Nginx proxy_cache
  • Nginx + PHP-FPM Fastcgi_cache
  • Varnish Cache
  • LiteSpeed Cache
  • Cloudflare Business and higher plan guest caching
I ask as XF 2.1 guest cache seems to still require requests to pass through PHP itself and that reduces the efficiency and performance of full page guest caching - I've seen it first hand with other web apps (wordpress/magento) that implement full page guest caching through PHP having only slightly better performance than without full page guest cache as opposed to when compared to doing full page guest caching where load is moved from PHP to the web server or web accelerator.
 
In below config where does $config['cache']['sessions'] = true; setting put the cached sessions ? looks like within the global cache instance ?
That just enables session caching.

Generally speaking, cached data will look if there's a specific cache context for it. If there isn't one specified, in most cases it will fallback to the global context. The fallback can be disabled on a per item basis in code -- we do this for page caching for the reasons I've laid out.
 
That just enables session caching.

Generally speaking, cached data will look if there's a specific cache context for it. If there isn't one specified, in most cases it will fallback to the global context. The fallback can be disabled on a per item basis in code -- we do this for page caching for the reasons I've laid out.
Cheers Mike :)
 
I think I have it configured correctly for redis caching on 2 instances of redis servers on port 6479 and 6480

In below config where does $config['cache']['sessions'] = true; setting put the cached sessions ? looks like within the global cache instance ?

PHP:
// https://xenforo.com/xf2-docs/manual/cache/
// global cache
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6480,
    'serializer' => 'igbinary',
//  'password' => 'password',
    'timeout' => 0.0,
    'database' => 3,
    'persistent' => true
];

// session cache
$config['cache']['sessions'] = true;

// guest page cache
$config['pageCache']['enabled'] = true;
$config['pageCache']['lifetime'] = 900;
$config['pageCache']['recordSessionActivity'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6479,
    'serializer' => 'igbinary',
    'database' => 5,
    'timeout' => 1,
    'persistent' => true
];

// css cache
// $config['css']['enabled'] = true;
$config['cache']['context']['css']['provider'] = 'Redis';
$config['cache']['context']['css']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6480,
    'serializer' => 'igbinary',
    'database' => 7,
    'timeout' => 1,
    'persistent' => true
];

View attachment 194858
View attachment 194859View attachment 194860

Do you have an article on your forum on setting up two Redis instances?
 
I think I have it configured correctly for redis caching on 2 instances of redis servers on port 6479 and 6480

In below config where does $config['cache']['sessions'] = true; setting put the cached sessions ? looks like within the global cache instance ?

PHP:
// https://xenforo.com/xf2-docs/manual/cache/
// global cache
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6480,
    'serializer' => 'igbinary',
//  'password' => 'password',
    'timeout' => 0.0,
    'database' => 3,
    'persistent' => true
];

// session cache
$config['cache']['sessions'] = true;

// guest page cache
$config['pageCache']['enabled'] = true;
$config['pageCache']['lifetime'] = 900;
$config['pageCache']['recordSessionActivity'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6479,
    'serializer' => 'igbinary',
    'database' => 5,
    'timeout' => 1,
    'persistent' => true
];

// css cache
// $config['css']['enabled'] = true;
$config['cache']['context']['css']['provider'] = 'Redis';
$config['cache']['context']['css']['config'] = [
    'host' => '127.0.0.1',
    'port' => 6480,
    'serializer' => 'igbinary',
    'database' => 7,
    'timeout' => 1,
    'persistent' => true
];

View attachment 194858
View attachment 194859View attachment 194860

This works perfectly. Also have 3 instances, two for XenForo and one for Wordpress.
 
Top Bottom