Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does Laravel store configuration for memcached session driver?

The Laravel docs specify that you can enable memcached as a session handler in app/config/session.php; however, it does not specify where memcached itself is configured (such as the servers to use).

I see that you can configure memcached in app/config/cache.php, but I don't know if that's used just for the Cache driver or for the session handler as well.

like image 719
Scott Buchanan Avatar asked Sep 10 '14 17:09

Scott Buchanan


1 Answers

Yes, the config in app/config/cache.php for your cache drivers is used for session driver as well.

Take a look at vendor/laravel/framework/src/Illuminate/Session/SessionManager.php. The method that creates an instance of the Memcached session driver is this one

/**
 * Create an instance of the Memcached session driver.
 *
 * @return \Illuminate\Session\Store
 */
protected function createMemcachedDriver()
{
    return $this->createCacheBased('memcached');
}

That method is calling this other method in the same file

/**
 * Create an instance of a cache driven driver.
 *
 * @param  string  $driver
 * @return \Illuminate\Session\Store
 */
protected function createCacheBased($driver)
{
    return $this->buildSession($this->createCacheHandler($driver)); //$driver = 'memcached'
}

Which is calling this other method in the same file

/**
 * Create the cache based session handler instance.
 *
 * @param  string  $driver
 * @return \Illuminate\Session\CacheBasedSessionHandler
 */
protected function createCacheHandler($driver)
{
    $minutes = $this->app['config']['session.lifetime'];

    return new CacheBasedSessionHandler($this->app['cache']->driver($driver), $minutes);
}

There you can see: this->app['cache']->driver($driver) which is actually getting your cache driver from the IoC container

like image 165
Javi Stolz Avatar answered Sep 24 '22 00:09

Javi Stolz