Skip to content
Permalink
Browse files

Updating session to lazy start after the first time an operation has …

…been performed. This should make controllers that only use sessions on some actions perform better.
  • Loading branch information...
markstory committed Dec 10, 2010
1 parent 9e1c85e commit 8eebdffcbb41faba84aa20019b61ea34fcbb4217
Showing with 22 additions and 4 deletions.
  1. +20 −1 cake/libs/cake_session.php
  2. +2 −3 cake/tests/cases/libs/cake_session.test.php
@@ -226,6 +226,9 @@ public static function started() {
* @return boolean True if variable is there
*/
public static function check($name = null) {
if (!self::started() && !self::start()) {
return false;
}
if (empty($name)) {
return false;
}
@@ -368,12 +371,15 @@ public static function userAgent($userAgent = null) {
* @return mixed The value of the session variable
*/
public static function read($name = null) {
if (empty($name)) {
if (!self::started() && !self::start()) {
return false;
}
if (is_null($name)) {
return self::__returnSessionVars();
}
if (empty($name)) {
return false;
}
$result = Set::classicExtract($_SESSION, $name);
if (!is_null($result)) {
@@ -403,6 +409,9 @@ private static function __returnSessionVars() {
* @return void
*/
public static function watch($var) {
if (!self::started() && !self::start()) {
return false;
}
if (empty($var)) {
return false;
}
@@ -418,6 +427,9 @@ public static function watch($var) {
* @return void
*/
public static function ignore($var) {
if (!self::started() && !self::start()) {
return false;
}
if (!in_array($var, self::$watchKeys)) {
return;
}
@@ -438,6 +450,9 @@ public static function ignore($var) {
* @return boolean True if the write was successful, false if the write failed
*/
public static function write($name, $value = null) {
if (!self::started() && !self::start()) {
return false;
}
if (empty($name)) {
return false;
}
@@ -666,6 +681,10 @@ protected static function _startSession() {
* @return void
*/
protected static function _checkValid() {
if (!self::started() && !self::start()) {
self::$valid = false;
return false;
}
if (self::read('Config')) {
$sessionConfig = Configure::read('Session');
@@ -305,8 +305,8 @@ function testWriteEmptyKey() {
* @return void
*/
function testId() {
$expected = session_id();
$result = TestCakeSession::id();
$expected = session_id();
$this->assertEqual($result, $expected);
TestCakeSession::id('MySessionId');
@@ -321,10 +321,9 @@ function testId() {
* @return void
*/
function testStarted() {
$this->assertTrue(TestCakeSession::started());
unset($_SESSION);
$_SESSION = null;
$this->assertFalse(TestCakeSession::started());
$this->assertTrue(TestCakeSession::start());
$this->assertTrue(TestCakeSession::started());

0 comments on commit 8eebdff

Please sign in to comment.
You can’t perform that action at this time.