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;
 

rdn

Well-known member
I would like to ask also.
I didn't found this on Manual Page.

Is this code correct?
Or something is redundant?

PHP:
// Cache
$config['cache']['sessions'] = true;
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
    'host' => '127.0.0.1',
    'database' => 2,
    'persistent' => true,
    'persistent_id' => 'pre_'
];
// Cache

// Guest Full Page Cache
$config['cache']['context']['page'] = [
        'provider' => 'Redis',
        'config' => ['server' => '127.0.0.1']
];
$config['pageCache']['enabled'] = true;
// Guest Full Page Cache
 

Mike

XenForo developer
Staff member
I will expand the caching section of the manual tomorrow to cover this, but @rdn's example would work. Note that you have to explicitly define a cache context for pages -- it won't go into the global cache automatically. This is because the page cache can potentially have a lot of data and it may interfere with things like session caching (which could lead to people not staying logged in). We would recommend a distinct caching "instance" for page caching (so it doesn't interact with the standard cache you've configured), unless you're sure that your cache is large enough to not run out of space.
 

rdn

Well-known member
The code I posted above doesn't work.
Here's what I have now:
PHP:
// Cache
$config['cache']['sessions'] = true;
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
    'host' => '127.0.0.1',
    'database' => 2,
    'persistent' => true,
    'persistent_id' => 'pre_'
];
// Cache

// Guest Full Page Cache
$config['pageCache']['enabled'] = true;
// Guest Full Page Cache

Basically I removed this:
PHP:
$config['cache']['context']['page'] = [
        'provider' => 'Redis',
        'config' => ['server' => '127.0.0.1']
];
 

Sunka

Well-known member
The code I posted above doesn't work.
Here's what I have now:
PHP:
// Cache
$config['cache']['sessions'] = true;
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
    'host' => '127.0.0.1',
    'database' => 2,
    'persistent' => true,
    'persistent_id' => 'pre_'
];
// Cache

// Guest Full Page Cache
$config['pageCache']['enabled'] = true;
// Guest Full Page Cache

Basically I removed this:
PHP:
$config['cache']['context']['page'] = [
        'provider' => 'Redis',
        'config' => ['server' => '127.0.0.1']
];
Is it working ?

So mine should look be like this:

Code:
// START Redis configuration //
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['namespace'] = 'xfredis_';

$config['cache']['provider'] = 'SV\RedisCache\Redis';
$config['cache']['config'] = array(
'server' => '127.0.0.1',
'port' => 6379,
'connect_retries' => 2,
'use_lua' => true,
'compress_data' => 2,
'read_timeout' => 1,
'timeout' => 1,
'serializer' => 'igbinary',
//        'serializer' => 'php',
);
// END Redis configuration //

// Guest Full Page Cache
$config['pageCache']['enabled'] = true;
// Guest Full Page Cache
 

Hristo Avramov

Active member
@Mike I am confused if I need to have some lines removed as $config['cache']['enabled'] = true; is 2 times now in my config? Which one is more right, to remove it or not?
Thanks!
Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
    'host' => '127.0.0.1',
    'port' => xxxxx,
];

$config['cache']['enabled'] = true;
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
    'host' => '127.0.0.1',
        'port' => xxxxx,
];
 
Last edited:

nodle

Well-known member
I am a tad confused. So say you are using Memcached, is this what you would add then?

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

Chromaniac

Well-known member
you would probably need to copy the config field value in the page config field as well.

this is what i did to my config.php:

PHP:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Apc';

$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Filesystem';
$config['cache']['context']['page']['config'] = ['directory' => '/home/forum/file_cache_xenforo'];

this seems to have worked for me. any feedback is appreciated!
 
Last edited:

nodle

Well-known member
I am still confused on setting this up, does this mean that I have to use a filesystem to store the separate cache in, if I am using memcache? Or is this something that memcache can store as well? I am using memcache currently. How would I go about incorprating both to work with memcache if possible?
 

Chromaniac

Well-known member
i am using filesystem by choice. i tried apc. i allocated 100MB to it. and 100MB filled up within 30 minutes. filesystem is probably slower than using APC on my server. but at least there is no shortage of space.

memcache should work fine. try it. and see if it works fine for you! xenforo developers mentioned above that they recommend using a separate instance though same works fine.

We would recommend a distinct caching "instance" for page caching (so it doesn't interact with the standard cache you've configured), unless you're sure that your cache is large enough to not run out of space.
 

nodle

Well-known member
So basically you would want each separated, like memcache doing the main caching and redis, or file system doing the guest caching? Is this correct? I know that IPS did guest caching but it was all tied in memcache all together.
 

Hristo Avramov

Active member
So basically you would want each separated, like memcache doing the main caching and redis, or file system doing the guest caching? Is this correct? I know that IPS did guest caching but it was all tied in memcache all together.
or 2 instances of redis. Think of it like you are having 2 fridges and you can store in 1 the cakes and in the other the fish :D
 

nodle

Well-known member
or 2 instances of redis. Think of it like you are having 2 fridges and you can store in 1 the cakes and in the other the fish :D

Say your using the standard memcached and then you add the code and point to the standard memcached port as well, isn't that using the same memcached instance? You basically just point two things at one location. Also is memcached limited on the amount it can store? Does guest caching take a lot of room in your memcached instance?

Would it look something like this:

$config['cache']['enabled'] = true;
$config['pageCache']['enabled'] = true;
$config['cache']['context']['page']['provider'] = 'Memcached';
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
'server' => '127.0.0.1'
];
 

Mike

XenForo developer
Staff member
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
 
Top