Cache support

For larger XenForo installations, it can be advantageous to define a cache in order to save on processing time and database queries.

XenForo has the ability to store and retrieve various data from a cache, which can be configured in your src/config.php file.

Supported providers

XenForo ships with several popular cache providers including:

  • APC
  • File system cache
  • Memcached
  • Redis
  • WinCache
  • XCache
  • ... and more!

Many of the cache providers will require software to be explicitly installed on your server. You may wish to inquire with your host as to which options are available.

Let's look at how to configure some of these cache providers. All configuration is done within src/config.php

APC

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

This provider has no additional configuration options.

File system cache

$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Filesystem';
$config['cache']['config'] = [
    'directory' => '/path/to/your/cache/directory'
];

Note

Ensure that the directory exists, is writable by the web server user, and is not publicly accessible!

Memcached

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

It is also possible to configure an array of servers, if required.

Redis

$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Redis';
$config['cache']['config'] = [
    'host' => '127.0.0.1',
    'password' => 'password'
];

Redis has a number of additional configuration options. The following list will demonstrate the default values of all of the supported configuration items available:

'host' => '',
'port' => 6379,
'timeout' => 0.0,
'password' => '',
'database' => 0,
'persistent' => false,
'persistent_id' => ''

WinCache

$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'WinCache';

This provider has no additional configuration options.

XCache

$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'XCache';

This provider has no additional configuration options.

Session caching

In addition to various data caches, it is possible to also cache XenForo user sessions. To cache sessions add the following to src/config.php:

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

Note

Your cache must have enough space to hold the sessions, or users may not be able to login properly. We do not recommend writing sessions to the cache if you are using APC as your cache provider.