namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
/**
- * MemcachedSessionHandler.
- *
* Memcached based session storage handler based on the Memcached class
* provided by the PHP memcached extension.
*
*
* @author Drak <drak@zikula.org>
*/
-class MemcachedSessionHandler implements \SessionHandlerInterface
+class MemcachedSessionHandler extends AbstractSessionHandler
{
- /**
- * @var \Memcached Memcached driver
- */
private $memcached;
/**
*
* List of available options:
* * prefix: The prefix to use for the memcached keys in order to avoid collision
- * * expiretime: The time to live in seconds
+ * * expiretime: The time to live in seconds.
*
* @param \Memcached $memcached A \Memcached instance
* @param array $options An associative array of Memcached options
/**
* {@inheritdoc}
*/
- public function open($savePath, $sessionName)
+ public function close()
{
return true;
}
/**
* {@inheritdoc}
*/
- public function close()
+ protected function doRead($sessionId)
{
- return true;
+ return $this->memcached->get($this->prefix.$sessionId) ?: '';
}
/**
* {@inheritdoc}
*/
- public function read($sessionId)
+ public function updateTimestamp($sessionId, $data)
{
- return $this->memcached->get($this->prefix.$sessionId) ?: '';
+ $this->memcached->touch($this->prefix.$sessionId, time() + $this->ttl);
+
+ return true;
}
/**
* {@inheritdoc}
*/
- public function write($sessionId, $data)
+ protected function doWrite($sessionId, $data)
{
return $this->memcached->set($this->prefix.$sessionId, $data, time() + $this->ttl);
}
/**
* {@inheritdoc}
*/
- public function destroy($sessionId)
+ protected function doDestroy($sessionId)
{
- return $this->memcached->delete($this->prefix.$sessionId);
+ $result = $this->memcached->delete($this->prefix.$sessionId);
+
+ return $result || \Memcached::RES_NOTFOUND == $this->memcached->getResultCode();
}
/**