简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM