From be463fdea686360fe57d877b851c46957f2751a1 Mon Sep 17 00:00:00 2001 From: Won-Kyu Park Date: Wed, 8 Jul 2015 09:46:51 +0900 Subject: [PATCH] Context::setCacheControl() method added etc. * make cache friendly * make cache-control public/private conditionally * use session_start() conditionally --- classes/context/Context.class.php | 36 ++++++++++++++++++++++-- classes/display/DisplayHandler.class.php | 15 ---------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index 09f7d09a1..492ca2443 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -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 * diff --git a/classes/display/DisplayHandler.class.php b/classes/display/DisplayHandler.class.php index deb8d8326..6b9f91e58 100644 --- a/classes/display/DisplayHandler.class.php +++ b/classes/display/DisplayHandler.class.php @@ -321,11 +321,6 @@ class DisplayHandler extends Handler 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"); } /** @@ -335,11 +330,6 @@ class DisplayHandler extends Handler 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"); } /** @@ -349,11 +339,6 @@ class DisplayHandler extends Handler 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"); } /**