You are here

public function SessionProxy_Storage_Cache::write in Session Proxy 7

Overrides SessionProxy_Storage_Interface::write

File

lib/SessionProxy/Storage/Cache.php, line 61

Class

SessionProxy_Storage_Cache
Storage implementation based upon a specific cache backend.

Code

public function write($sessionId, $serializedData) {
  global $user;
  try {

    // For performance reasons, do not update the sessions table, unless
    // $_SESSION has changed or more than 180 has passed since the last update.
    if ($this
      ->sessionDataHasChanged($sessionId, $serializedData)) {
      $cid = $this
        ->getCid($sessionId);

      // Either ssid or sid or both will be added from $key below.
      $data = new stdClass();
      $data->uid = $this->uid;
      $data->session = $serializedData;
      $this->cacheBackend
        ->set($cid, $data);
    }
    return TRUE;
  } catch (Exception $exception) {

    // FIXME: This should never be here, a global try/catch should definitely
    // be done upper in the code.
    require_once DRUPAL_ROOT . '/includes/errors.inc';

    // If we are displaying errors, then do so with no possibility of a further
    // uncaught exception being thrown.
    if (error_displayable()) {
      print '<h1>Uncaught exception thrown in session handler.</h1>';
      print '<p>' . _drupal_render_exception_safe($exception) . '</p><hr />';
    }
    return FALSE;
  }
}