1
0
Fork 0
friendica_2020-09-1_sharedH.../src/Factory/CacheDriverFactory.php

51 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2019-03-03 15:05:35 +01:00
namespace Friendica\Factory;
2019-03-03 15:05:35 +01:00
use Friendica\Core\Cache\ICacheDriver;
use Friendica\Core\Config;
2019-03-03 15:05:35 +01:00
use Friendica\Core\Cache;
/**
* Class CacheDriverFactory
*
* @package Friendica\Core\Cache
*
2018-07-05 07:59:56 +02:00
* A basic class to generate a CacheDriver
*/
class CacheDriverFactory
{
/**
2018-07-05 07:59:56 +02:00
* This method creates a CacheDriver for the given cache driver name
*
* @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
*/
public static function create($driver) {
switch ($driver) {
case 'memcache':
$memcache_host = Config::get('system', 'memcache_host');
$memcache_port = Config::get('system', 'memcache_port');
2019-03-03 15:05:35 +01:00
return new Cache\MemcacheCacheDriver($memcache_host, $memcache_port);
break;
case 'memcached':
$memcached_hosts = Config::get('system', 'memcached_hosts');
2019-03-03 15:05:35 +01:00
return new Cache\MemcachedCacheDriver($memcached_hosts);
break;
case 'redis':
$redis_host = Config::get('system', 'redis_host');
$redis_port = Config::get('system', 'redis_port');
2019-03-03 15:05:35 +01:00
return new Cache\RedisCacheDriver($redis_host, $redis_port);
break;
default:
2019-03-03 15:05:35 +01:00
return new Cache\DatabaseCacheDriver();
}
}
}