mirror of
https://github.com/e107inc/e107.git
synced 2025-08-04 13:47:31 +02:00
fixes #5 - browser cache now better managed and manually enabled per page and per user session via e107::canCache()
This commit is contained in:
@@ -2937,6 +2937,46 @@ class e107
|
|||||||
|
|
||||||
define('e_TBQS', $_SERVER['QUERY_STRING']);
|
define('e_TBQS', $_SERVER['QUERY_STRING']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic implementation of Browser cache control per user session. Awaiting improvement in future versions
|
||||||
|
* If no argument is passed it returns
|
||||||
|
* boolean (if current page is cacheable).
|
||||||
|
* If string is passed, it's asumed to be aboslute request path (e_REQUEST_URI alike)
|
||||||
|
* If true is passed, e_REQUEST_URI is registered
|
||||||
|
*/
|
||||||
|
public static function canCache($set = null)
|
||||||
|
{
|
||||||
|
$_data = e107::getSession()->get('__sessionBrowserCache');
|
||||||
|
if(!is_array($_data)) $_data = array();
|
||||||
|
|
||||||
|
if(null === $set)
|
||||||
|
{
|
||||||
|
return in_array(e_REQUEST_URI, $_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove e_REQUEST_URI from the set
|
||||||
|
if(false === $set)
|
||||||
|
{
|
||||||
|
$check = array_search(e_REQUEST_URI, $_data);
|
||||||
|
if(false !== $check)
|
||||||
|
{
|
||||||
|
unset($_data[$check]);
|
||||||
|
e107::getSession()->set('__sessionBrowserCache', $_data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(true === $set)
|
||||||
|
{
|
||||||
|
$set = e_REQUEST_URI;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(empty($set) || !is_string($set) || in_array($set, $_data)) return;
|
||||||
|
|
||||||
|
$_data[] = $set;
|
||||||
|
e107::getSession()->set('__sessionBrowserCache', array_unique($_data));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if current request is secure (https)
|
* Check if current request is secure (https)
|
||||||
|
@@ -27,9 +27,10 @@ e107::getSession()->shutdown();
|
|||||||
// System browser CACHE control - defaults to no cache; override in e107_config or on the fly
|
// System browser CACHE control - defaults to no cache; override in e107_config or on the fly
|
||||||
// This is temporary solution, we'll implement more flexible way for cache control override
|
// This is temporary solution, we'll implement more flexible way for cache control override
|
||||||
// per page, more investigation needed about cache related headers, browser quirks etc
|
// per page, more investigation needed about cache related headers, browser quirks etc
|
||||||
|
// Auto-detect from session (registered per page, per user session)
|
||||||
if(!defined('e_NOCACHE'))
|
if(!defined('e_NOCACHE'))
|
||||||
{
|
{
|
||||||
define('e_NOCACHE', true);
|
define('e_NOCACHE', !e107::canCache());
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -306,7 +307,14 @@ if (abs($_serverTime - $lastSet) > 120)
|
|||||||
// H Final HTML
|
// H Final HTML
|
||||||
//
|
//
|
||||||
// browser cache control - FIXME - use this value as AJAX requests cache control!
|
// browser cache control - FIXME - use this value as AJAX requests cache control!
|
||||||
echo "\n<!-- ".md5(deftrue('e_NOCACHE') ? time() : e107::getPref('e_jslib_browser_cache'))." -->\n";
|
// TODO - create the $bcache string via e107 class method, use it in the canCache() method
|
||||||
|
$uclist = e107::getUser()->getClassList();
|
||||||
|
sort($uclist, SORT_NUMERIC);
|
||||||
|
$bcache = (deftrue('e_NOCACHE') ? time() : e107::getPref('e_jslib_browser_cache')).'.'.implode(',', $uclist);
|
||||||
|
echo "\n<!-- ".md5($bcache)." -->\n";
|
||||||
|
|
||||||
|
unset($uclist, $bcache);
|
||||||
|
|
||||||
if(!deftrue('e_POWEREDBY_DISABLE'))
|
if(!deftrue('e_POWEREDBY_DISABLE'))
|
||||||
{
|
{
|
||||||
// TODO lan
|
// TODO lan
|
||||||
@@ -323,10 +331,9 @@ $etag = md5($page);
|
|||||||
|
|
||||||
//header('Pragma:');
|
//header('Pragma:');
|
||||||
// previously disabled or there is posted data
|
// previously disabled or there is posted data
|
||||||
$canCache = false;
|
$canCache = e107::canCache();
|
||||||
if(!deftrue('e_NOCACHE') && $_SERVER['REQUEST_METHOD'] === 'GET' && $_SERVER['QUERY_STRING'] != 'logout')
|
if($canCache && !deftrue('e_NOCACHE') && $_SERVER['REQUEST_METHOD'] === 'GET' && $_SERVER['QUERY_STRING'] != 'logout')
|
||||||
{
|
{
|
||||||
$canCache = true;
|
|
||||||
header("Cache-Control: must-revalidate", true);
|
header("Cache-Control: must-revalidate", true);
|
||||||
if(e107::getPref('site_page_expires')) // TODO - allow per page
|
if(e107::getPref('site_page_expires')) // TODO - allow per page
|
||||||
{
|
{
|
||||||
@@ -338,6 +345,10 @@ if(!deftrue('e_NOCACHE') && $_SERVER['REQUEST_METHOD'] === 'GET' && $_SERVER['QU
|
|||||||
header('Expires: '.gmdate("D, d M Y H:i:s", $time).' GMT', true);
|
header('Expires: '.gmdate("D, d M Y H:i:s", $time).' GMT', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$canCache = false;
|
||||||
|
}
|
||||||
|
|
||||||
$pref['compression_level'] = 6;
|
$pref['compression_level'] = 6;
|
||||||
$browser_support = FALSE;
|
$browser_support = FALSE;
|
||||||
@@ -379,7 +390,6 @@ header("X-Powered-By: e107", true); // no less secure than e107-specific html.
|
|||||||
if ($canCache && isset($_SERVER['HTTP_IF_NONE_MATCH']))
|
if ($canCache && isset($_SERVER['HTTP_IF_NONE_MATCH']))
|
||||||
{
|
{
|
||||||
$IF_NONE_MATCH = str_replace('"','',$_SERVER['HTTP_IF_NONE_MATCH']);
|
$IF_NONE_MATCH = str_replace('"','',$_SERVER['HTTP_IF_NONE_MATCH']);
|
||||||
|
|
||||||
if($IF_NONE_MATCH == $etag || ($IF_NONE_MATCH == ($etag."-gzip")))
|
if($IF_NONE_MATCH == $etag || ($IF_NONE_MATCH == ($etag."-gzip")))
|
||||||
{
|
{
|
||||||
header('HTTP/1.1 304 Not Modified');
|
header('HTTP/1.1 304 Not Modified');
|
||||||
|
Reference in New Issue
Block a user