Created
December 30, 2013 15:01
-
-
Save ericsk/8183069 to your computer and use it in GitHub Desktop.
WindowsAzureSessionHandler 的 Write 方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Callback function for session handler. It's invoked while the session data is being written. | |
* | |
* @param $sessionId The session ID. | |
* @param $sessionData The data to be written in session. | |
* | |
* @return boolean If the write operation success. | |
*/ | |
public function write($sessionId, $sessionData) { | |
// serialize and encode the session data. | |
$serializedData = base64_encode(serialize($sessionData)); | |
try { | |
// try to retrive the stored session entity and update it. | |
$result = $this->_tableRestProxy->getEntity($this->_sessionContainer, $this->_sessionContainerPartition, $sessionId); | |
$entity = $result->getEntity(); | |
// update data and expiry time | |
$entity->setPropertyValue('data', $serializedData); | |
$entity->setPropertyValue('expires', time()); | |
// update entity | |
$this->_tableRestProxy->updateEntity($this->_sessionContainer, $entity); | |
} catch (ServiceException $e) { | |
// otherwise, create a new session entity to store the data. | |
$entity = new Entity(); | |
// set partition key and use session id as the row key. | |
$entity->setPartitionKey($this->_sessionContainerPartition); | |
$entity->setRowKey($sessionId); | |
// set data and expiry time | |
$entity->addProperty('data', EdmType::STRING, $serializedData); | |
$entity->addProperty('expires', EdmType::INT32, time()); | |
// insert the entity | |
$this->_tableRestProxy->insertEntity($this->_sessionContainer, $entity); | |
} | |
return TRUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment