Newscoop\Services\CacheService::getCacheDriver PHP Метод

getCacheDriver() публичный Метод

Get cache driver instance
public getCacheDriver ( ) : CacheProvider
Результат Doctrine\Common\Cache\CacheProvider
    public function getCacheDriver()
    {
        if (!is_null($this->cacheDriver)) {
            return $this->cacheDriver;
        }
        if (php_sapi_name() === 'cli') {
            return $this->cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
        }
        try {
            switch ($this->systemPreferences->get('DBCacheEngine', 'Array')) {
                case 'apc':
                    $this->cacheDriver = new \Doctrine\Common\Cache\ApcCache();
                    break;
                case 'memcache':
                    $memcache = new \Memcache();
                    $memcache->connect($this->systemPreferences->get('DBCacheEngineHost', '127.0.0.1'), $this->systemPreferences->get('DBCacheEnginePort', '11211'));
                    $this->cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
                    $this->cacheDriver->setMemcache($memcache);
                    break;
                case 'memcached':
                    $memcached = new \Memcached();
                    $memcached->addServer($this->systemPreferences->get('DBCacheEngineHost', '127.0.0.1'), $this->systemPreferences->get('DBCacheEnginePort', '11211'));
                    $this->cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
                    $this->cacheDriver->setMemcached($memcached);
                    break;
                case 'xcache':
                    $this->cacheDriver = new \Doctrine\Common\Cache\XcacheCache();
                    break;
                case 'redis':
                    $redis = new \Redis();
                    $redis->connect($this->systemPreferences->get('DBCacheEngineHost', '127.0.0.1'), $this->systemPreferences->get('DBCacheEnginePort', '6379'));
                    $this->cacheDriver = new \Doctrine\Common\Cache\RedisCache();
                    $this->cacheDriver->setRedis($redis);
                    break;
                default:
                    $this->cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
                    break;
            }
        } catch (\Exception $e) {
            $this->cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
        }
        return $this->cacheDriver;
    }