Skip to content

Commit

Permalink
Context::setCacheControl() method added etc.
Browse files Browse the repository at this point in the history
 * make cache friendly
 * make cache-control public/private conditionally
 * use session_start() conditionally
  • Loading branch information
wkpark committed Jul 8, 2015
1 parent eaf3a23 commit cd3d1b2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
36 changes: 34 additions & 2 deletions classes/context/Context.class.php
Expand Up @@ -333,8 +333,20 @@ function init()
);
}

if($sess = $_POST[session_name()]) session_id($sess);
session_start();
$sessid = session_name();
if($sess = $_POST[$sessid]) session_id($sess);
else $sess = $_COOKIE[$sessid];

session_cache_limiter(''); // to control the cache-control header manually
if(!empty($sess))
{
Context::setCacheControl('private', true);
session_start();
}
else
{
Context::setCacheControl();
}

// set authentication information in Context and session
if(self::isInstalled())
Expand Down Expand Up @@ -430,6 +442,26 @@ function close()
session_write_close();
}

/**
* set Cache-Control header
*
* @return void
*/
function setCacheControl($public = 'public', $nocache = false)
{
is_a($this, 'Context') ? $self = $this : $self = self::getInstance();

$public = !empty($public) ? $public.', ' : '';
header("Cache-Control: ".$public."must-revalidate, post-check=0, pre-check=0");
if ($nocache)
{
header("Cache-Control: no-store, no-cache, must-revalidate", false);
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");
}
}

/**
* Load the database information
*
Expand Down
15 changes: 0 additions & 15 deletions classes/display/DisplayHandler.class.php
Expand Up @@ -321,11 +321,6 @@ function _debugOutput()
function _printXMLHeader()
{
header("Content-Type: text/xml; charset=UTF-8");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}

/**
Expand All @@ -335,11 +330,6 @@ function _printXMLHeader()
function _printHTMLHeader()
{
header("Content-Type: text/html; charset=UTF-8");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}

/**
Expand All @@ -349,11 +339,6 @@ function _printHTMLHeader()
function _printJSONHeader()
{
header("Content-Type: text/html; charset=UTF-8");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}

/**
Expand Down
3 changes: 3 additions & 0 deletions modules/member/member.controller.php
Expand Up @@ -1661,6 +1661,9 @@ function doLogin($user_id, $password = '', $keep_signed = false)
$trigger_obj->password = $password;
$trigger_output = ModuleHandler::triggerCall('member.doLogin', 'before', $trigger_obj);
if(!$trigger_output->toBool()) return $trigger_output;

session_start();

// Create a member model object
$oMemberModel = getModel('member');

Expand Down

0 comments on commit cd3d1b2

Please sign in to comment.