2018-06-28 22:57:17 +02:00
|
|
|
<?php
|
|
|
|
|
2019-03-03 15:05:35 +01:00
|
|
|
namespace Friendica\Factory;
|
2018-06-28 22:57:17 +02:00
|
|
|
|
2019-04-20 13:40:40 +02:00
|
|
|
use Friendica\Core\Cache;
|
2019-03-03 15:05:35 +01:00
|
|
|
use Friendica\Core\Cache\ICacheDriver;
|
2018-06-28 22:57:17 +02:00
|
|
|
use Friendica\Core\Config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CacheDriverFactory
|
|
|
|
*
|
|
|
|
* @package Friendica\Core\Cache
|
|
|
|
*
|
2018-07-05 07:59:56 +02:00
|
|
|
* A basic class to generate a CacheDriver
|
2018-06-28 22:57:17 +02:00
|
|
|
*/
|
|
|
|
class CacheDriverFactory
|
|
|
|
{
|
|
|
|
/**
|
2018-07-05 07:59:56 +02:00
|
|
|
* This method creates a CacheDriver for the given cache driver name
|
2018-06-28 22:57:17 +02:00
|
|
|
*
|
|
|
|
* @param string $driver The name of the cache driver
|
|
|
|
* @return ICacheDriver The instance of the CacheDriver
|
|
|
|
* @throws \Exception The exception if something went wrong during the CacheDriver creation
|
|
|
|
*/
|
2018-06-28 23:06:14 +02:00
|
|
|
public static function create($driver) {
|
2018-06-28 22:57:17 +02:00
|
|
|
|
|
|
|
switch ($driver) {
|
|
|
|
case 'memcache':
|
2018-07-17 08:05:06 +02:00
|
|
|
$memcache_host = Config::get('system', 'memcache_host');
|
|
|
|
$memcache_port = Config::get('system', 'memcache_port');
|
2018-06-28 22:57:17 +02:00
|
|
|
|
2019-03-03 15:05:35 +01:00
|
|
|
return new Cache\MemcacheCacheDriver($memcache_host, $memcache_port);
|
2018-06-28 22:57:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'memcached':
|
2018-07-17 08:05:06 +02:00
|
|
|
$memcached_hosts = Config::get('system', 'memcached_hosts');
|
2018-06-28 22:57:17 +02:00
|
|
|
|
2019-03-03 15:05:35 +01:00
|
|
|
return new Cache\MemcachedCacheDriver($memcached_hosts);
|
2018-06-28 22:57:17 +02:00
|
|
|
break;
|
|
|
|
case 'redis':
|
2018-07-17 08:05:06 +02:00
|
|
|
$redis_host = Config::get('system', 'redis_host');
|
|
|
|
$redis_port = Config::get('system', 'redis_port');
|
2019-04-20 13:40:40 +02:00
|
|
|
$redis_pw = Config::get('system', 'redis_password');
|
|
|
|
$redis_db = Config::get('system', 'redis_db', 0);
|
2018-06-28 22:57:17 +02:00
|
|
|
|
2019-04-20 13:40:40 +02:00
|
|
|
return new Cache\RedisCacheDriver($redis_host, $redis_port, $redis_db, $redis_pw);
|
2018-06-28 22:57:17 +02:00
|
|
|
break;
|
2019-04-20 17:37:57 +02:00
|
|
|
|
|
|
|
case 'apcu':
|
|
|
|
return new Cache\APCuCache();
|
|
|
|
break;
|
|
|
|
|
2018-06-28 22:57:17 +02:00
|
|
|
default:
|
2019-03-03 15:05:35 +01:00
|
|
|
return new Cache\DatabaseCacheDriver();
|
2018-06-28 22:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|