2011-08-18 19:56:29 -05:00
|
|
|
<?php namespace Laravel\Session;
|
2011-06-08 23:45:08 -05:00
|
|
|
|
2011-08-19 20:12:39 -05:00
|
|
|
class Memcached extends Driver {
|
2011-06-08 23:45:08 -05:00
|
|
|
|
2011-08-25 22:53:05 -05:00
|
|
|
/**
|
|
|
|
|
* The Memcache cache driver instance.
|
|
|
|
|
*
|
|
|
|
|
* @var Memcached
|
|
|
|
|
*/
|
|
|
|
|
private $memcached;
|
|
|
|
|
|
2011-08-26 21:42:04 -05:00
|
|
|
/**
|
|
|
|
|
* The session lifetime.
|
|
|
|
|
*
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
private $lifetime;
|
|
|
|
|
|
2011-08-25 22:53:05 -05:00
|
|
|
/**
|
|
|
|
|
* Create a new Memcached session driver instance.
|
|
|
|
|
*
|
|
|
|
|
* @param Memcached $memcached
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2011-08-26 21:42:04 -05:00
|
|
|
public function __construct(\Laravel\Cache\Memcached $memcached, $lifetime)
|
2011-08-25 22:53:05 -05:00
|
|
|
{
|
2011-08-26 21:42:04 -05:00
|
|
|
$this->lifetime = $lifetime;
|
2011-08-25 22:53:05 -05:00
|
|
|
$this->memcached = $memcached;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a session by ID.
|
|
|
|
|
*
|
|
|
|
|
* The session will be retrieved from persistant storage and returned as an array.
|
|
|
|
|
* The array contains the session ID, last activity UNIX timestamp, and session data.
|
|
|
|
|
*
|
|
|
|
|
* @param string $id
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2011-08-19 20:12:39 -05:00
|
|
|
protected function load($id)
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-08-25 22:53:05 -05:00
|
|
|
return $this->memcached->get($id);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
2011-08-25 22:53:05 -05:00
|
|
|
/**
|
|
|
|
|
* Save the session to persistant storage.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2011-08-19 20:12:39 -05:00
|
|
|
protected function save()
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-08-26 21:42:04 -05:00
|
|
|
$this->memcached->put($this->session['id'], $this->session, $this->lifetime);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
2011-08-25 22:53:05 -05:00
|
|
|
/**
|
|
|
|
|
* Delete the session from persistant storage.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2011-08-19 20:12:39 -05:00
|
|
|
protected function delete()
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-08-25 22:53:05 -05:00
|
|
|
$this->memcached->forget($this->session['id']);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|