$config['cache']['enabled'] = true;
$config['cache']['namespace'] = 'xf_';
$config['cache']['sessions'] = true;
$config['cache']['config'] = [
'host' => '127.0.0.1'
];
$config['cache']['provider'] = function(array $config)
{
if (!class_exists('Redis'))
{
throw new \LogicException("Cannot load Redis cache provider without Redis");
}
$config = array_replace([
'host' => '',
'port' => 6379,
'timeout' => 0.0,
'password' => '',
'database' => 0,
'persistent' => false,
'persistent_id' => ''
], $config);
$r = new \Redis();
if ($config['persistent'])
{
$r->pconnect($config['host'], $config['port'], $config['timeout'], $config['persistent_id']);
}
else
{
$r->connect($config['host'], $config['port'], $config['timeout']);
}
if ($config['password'])
{
$r->auth($config['password']);
}
if ($config['database'])
{
$r->select($config['database']);
}
$cache = new \Doctrine\Common\Cache\RedisCache();
$cache->setRedis($r);
return $cache;
};