Context::setCacheControl() method added etc.

* make cache friendly
 * make cache-control public/private conditionally
 * use session_start() conditionally
This commit is contained in:
Won-Kyu Park 2015-07-08 09:46:51 +09:00
parent be25911b72
commit be463fdea6
2 changed files with 34 additions and 17 deletions

View file

@ -333,8 +333,20 @@ class Context
);
}
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())
@ -430,6 +442,26 @@ class Context
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
*