create memcached session driver
throw SessionException when session save path is not exists

@return CacheSessionHandler
351977
protected function createMemcacheDriver()
    {
        $serverArray    = $this->config['servers'];
        $persistent     = boolval($this->config['persistent']);
        $name           = trim($this->config['server_name']);
        $prefix         = trim($this->config['prefix']);
        $expireTime     = intval($this->config['lifetime']);

        if ($persistent && (strlen($name) > 0)) {
            $memcached  = new Memcached($name);
        } else {
            $memcached  = new Memcached();
        }

        if (!sizeof($memcached->getServerList())) {
            $memcached->addServers($serverArray);
        }

        $store = new MemcachedStore($memcached, $prefix);
        return new CacheSessionHandler($store, $expireTime);
    }
508805
private function getEndpointsCache() 
    {
        if ($this->_cache === null) {
            if (!isset($this->_values[self::OPTION_MEMCACHED_SERVERS])) {
                return null;
            }
            if (!class_exists('Memcached', false)) {
                return null;
            }

            $servers = $this->_values[self::OPTION_MEMCACHED_SERVERS];
            if (!is_array($servers)) {
                throw new ClientException('Invalid memcached servers list. should be an array of servers');
            }

            $cache = new \Memcached(self::OPTION_MEMCACHED_PERSISTENT_ID);
            if (empty($cache->getServerList())) {
                $cache->addServers($servers);
            }
            
            if (isset($this->_values[self::OPTION_MEMCACHED_OPTIONS])) {
                $options = $this->_values[self::OPTION_MEMCACHED_OPTIONS];
                if (!is_array($options)) {
                    throw new ClientException('Invalid memcached options list. should be an array of options');
                }
                $cache->setOptions($options);
            }

            $this->_cache = $cache;
        
        }
        return $this->_cache;
    }
1215490
private function create(): CookieAuthSession
    {
        $response = $this->request($this->endpoint . $this->path, [
            RequestOptions::JSON => [
                'username' => $this->username,
                'password' => $this->password,
            ],
        ]);

        $body = $response->getBody();
        $body->seek(0);
        $contents = $body->getContents();

        $contents = json_decode($contents, true);

        if (isset($contents['session']['name'], $contents['session']['value'])) {
            return new CookieAuthSession($contents['session']['name'], $contents['session']['value']);
        }

        throw new \Exception('Failed to create ' . CookieAuthSession::class . '.');
    }
242445
protected function addRedisSentinelSessionHandler()
    {
        $this->app->make('session')->extend('redis-sentinel', function ($app) {
            $cacheDriver = clone $app->make('cache')->driver('redis-sentinel');
            $minutes = $this->config->get('session.lifetime');
            $connection = $this->config->get('session.connection');

            $cacheDriver->getStore()->setConnection($connection);

            return new CacheBasedSessionHandler($cacheDriver, $minutes);
        });
    }
863634
public function write($session_id, $session_data)
    {
        return $this->memcached->set($session_id, $session_data, $this->expire);
    }
960970
public static function getSession()
    {
        if (is_null(self::$session)) {
            if (PHPSession::singleton()->hasAttribute(self::PHPSESSION_SESSION_KEY)) {
                $session = PHPSession::singleton()->getAttribute(self::PHPSESSION_SESSION_KEY);
                if (! $session instanceof common_session_Session) {
                    throw new common_exception_Error('Non session stored in php-session');
                }
                self::$session = $session;
            } else {
                self::$session = new common_session_AnonymousSession();
            }
        }
        if (self::$session instanceof ServiceLocatorAwareInterface) {
            self::$session->setServiceLocator(ServiceManager::getServiceManager());
        }
        return self::$session;
    }
308775
public function getHandleFromCache()
    {
        $fileID = $this->getCacheID();
        if (!$this->isCached($fileID)) {
            $this->saveOriginalImageToCache($fileID);
        }

        return $this->makeImage(
            $this->storagePath(
                $this->generateCacheFilePath($fileID)
            )
        );
    }
595631
public function getMemcache()
    {
        if ($this->_cache === null) {
            $extension = $this->useMemcached ? 'memcached' : 'memcache';
            if (!extension_loaded($extension)) {
                throw new InvalidConfigException("MemCache requires PHP $extension extension to be loaded.");
            }

            if ($this->useMemcached) {
                $this->_cache = $this->persistentId !== null ? new \Memcached($this->persistentId) : new \Memcached;
                if ($this->username !== null || $this->password !== null) {
                    $this->_cache->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
                    $this->_cache->setSaslAuthData($this->username, $this->password);
                }
                if (!empty($this->options)) {
                    $this->_cache->setOptions($this->options);
                }
            } else {
                $this->_cache = new \Memcache;
            }
        }

        return $this->_cache;
    }
863255
public static function me() {
        if (CLI) throw new IllegalStateException('Can not use '.static::class.' in this context.');

        $cache = Cache::me();

        // cache hit?
        $controller = $cache->get(static::class);
        if (!$controller) {
            // synchronize parsing of the struts-config.xml                 // TODO: Don't lock on the config file because it can block
            // $lock = new FileLock($configFile);                           //       concurrent reads, see Todo-File at locking.
            //                                                              //
            // $controller = $cache->get($class);                           // re-check after the lock is aquired

                if (!$controller) {
                    $controller = self::getInstance(static::class);
                    $configDir  = self::di('config')['app.dir.config'];
                    $configFile = str_replace('\\', '/', $configDir.'/struts-config.xml');
                    $dependency = FileDependency::create($configFile);
                    if (!WINDOWS && !LOCALHOST)                             // distinction dev/production?  TODO: non-sense
                        $dependency->setMinValidity(1 * MINUTE);

                    // ...and cache it with a FileDependency
                    $cache->set(static::class, $controller, Cache::EXPIRES_NEVER, $dependency);
                }

            //$lock->release();
        }
        return $controller;
    }
406583
protected function createRedisDriver()
    {
        $handler = $this->createCacheHandler('redis');
        if (!is_a($handler->getCache()->getStore(), RedisStore::class)) {
            throw new \UnexpectedValueException('Wrong cache driver found');
        }
        $handler->getCache()->getStore()->getRedis()->ping();
        $handler->getCache()->getStore()->setConnection($this->app['config']['session.connection']);
        return $this->buildSession($handler);
    }
1073821
public function getCache()
    {
        if (null === self::$cache) {
            if (!empty($this->appConfig['cache']['driver'])) {
                // Options definition.
                if (empty($this->appConfig['cache']['options'])) {
                    $options = array();
                } else {
                    $options = $this->appConfig['cache']['options'];
                }

                // Driver definition.
                if ('memcached' !== $this->appConfig['cache']['driver']) {
                    $className = $this->appConfig['cache']['driver'];
                } else {
                    $className = '\Towel\Cache\TowelMemcached';
                }

                // Driver instantiation
                $cacheDriver = new $className();
                $cacheDriver->setOptions($options);
            }

            self::$cache = new TowelCache($cacheDriver);
        }

        return self::$cache;
    }
1325561
protected Cache<String, SessionData> create(String name, long idleTime) {
        return Caching
                .getCachingProvider()
                .getCacheManager()
                .createCache(
                        name,
                        new MutableConfiguration<String, SessionData>()
                        .setTypes(String.class, SessionData.class)
                        .setExpiryPolicyFactory(
                                TouchedExpiryPolicy.factoryOf(
                                        new Duration(
                                                TimeUnit.SECONDS,
                                                idleTime))));
    }
1315795
protected function createCacheHandler( $driver )
	{
		return new CacheBasedSessionHandler( clone CacheManager::i()->driver( $driver ), Config::get( $this->configPrefix . '.lifetime' ) );
	}
435322
public static function createFrom(
        Storage $persistenceProvider,
        Storage $cacheProvider,
        LoggerInterface $logger = null
    ) {
        /** @var $userAgentHandlerChain \Wurfl\Handlers\Chain\UserAgentHandlerChain */
        $userAgentHandlerChain = $cacheProvider->load('UserAgentHandlerChain');

        if (!($userAgentHandlerChain instanceof UserAgentHandlerChain)) {
            $userAgentHandlerChain = self::init();
            $cacheProvider->save('UserAgentHandlerChain', $userAgentHandlerChain, 3600);
        }

        $userAgentHandlerChain->setLogger($logger);

        foreach ($userAgentHandlerChain->getHandlers() as $handler) {
            /* @var $handler \Wurfl\Handlers\AbstractHandler */
            $handler
                ->setLogger($logger)
                ->setPersistenceProvider($persistenceProvider);
        }

        return $userAgentHandlerChain;
    }
493241
protected function cachePool()
    {
        if ($this->cachePool === null) {
            throw new RuntimeException(sprintf(
                'Cache Pool is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->cachePool;
    }
1212597
public static MemcachedManagerBuilder memcachierAddOn() {
        final String memcachierServers = System.getenv("MEMCACHIER_SERVERS");
        return memcachedConfig()
                .username(System.getenv("MEMCACHIER_USERNAME"))
                .password(System.getenv("MEMCACHIER_PASSWORD"))
                .url(memcachierServers == null ? DEFAULT_URL : memcachierServers);
    }
548862
private function connect()
	{
		// We want to only create the driver once.
		if ($this->driver)
		{
			return;
		}

		$pool = $this->options['memcache.pool'];

		if ($pool)
		{
			$this->driver = new \Memcached($pool);
		}
		else
		{
			$this->driver = new \Memcached;
		}

		$this->driver->setOption(\Memcached::OPT_COMPRESSION, $this->options['memcache.compress'] ?: false);
		$this->driver->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
		$serverList = $this->driver->getServerList();

		// If we are using a persistent pool we don't want to add the servers again.
		if (empty($serverList))
		{
			$servers = $this->options['memcache.servers'] ?: array();

			foreach ($servers as $server)
			{
				$this->driver->addServer($server->host, $server->port);
			}
		}
	}