mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Renamed some functions in cache manager, now unloads vars properly before the page is output.
git-svn-id: file:///svn/phpbb/trunk@3479 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
389095086d
commit
0101c669cc
5 changed files with 59 additions and 50 deletions
|
@ -131,7 +131,7 @@ function page_footer($copyright_html = true)
|
||||||
|
|
||||||
if (!empty($cache))
|
if (!empty($cache))
|
||||||
{
|
{
|
||||||
$cache->save_cache();
|
$cache->unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
|
@ -145,10 +145,12 @@ $user = new user();
|
||||||
$auth = new auth();
|
$auth = new auth();
|
||||||
|
|
||||||
// Need these here so instantiate them now
|
// Need these here so instantiate them now
|
||||||
$cache = new acm();// Experimental cache manager
|
$cache = new acm();
|
||||||
$template = new template();
|
$template = new template();
|
||||||
$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false);
|
$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false);
|
||||||
|
|
||||||
|
// 20030218 Ashe: $dbport is not set by the installer
|
||||||
|
|
||||||
// Grab global variables, re-cache if necessary
|
// Grab global variables, re-cache if necessary
|
||||||
if ($config = $cache->get('config'))
|
if ($config = $cache->get('config'))
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,6 +34,39 @@ class acm
|
||||||
$this->cache_dir = $phpbb_root_path . 'cache/';
|
$this->cache_dir = $phpbb_root_path . 'cache/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function load()
|
||||||
|
{
|
||||||
|
global $phpEx;
|
||||||
|
@include($this->cache_dir . 'global.' . $phpEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unload()
|
||||||
|
{
|
||||||
|
$this->save();
|
||||||
|
unset($this->vars);
|
||||||
|
unset($this->vars_ts);
|
||||||
|
unset($this->sql_rowset);
|
||||||
|
}
|
||||||
|
|
||||||
|
function save()
|
||||||
|
{
|
||||||
|
if (!$this->modified)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
global $phpEx;
|
||||||
|
$file = '<?php $this->vars=' . $this->format_array($this->vars) . ";\n\$this->vars_ts=" . $this->format_array($this->vars_ts) . ' ?>';
|
||||||
|
|
||||||
|
if ($fp = @fopen($this->cache_dir . 'global.' . $phpEx, 'wb'))
|
||||||
|
{
|
||||||
|
@flock($fp, LOCK_EX);
|
||||||
|
fwrite($fp, $file);
|
||||||
|
@flock($fp, LOCK_UN);
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function tidy($expire_time = 0)
|
function tidy($expire_time = 0)
|
||||||
{
|
{
|
||||||
global $phpEx;
|
global $phpEx;
|
||||||
|
@ -41,11 +74,11 @@ class acm
|
||||||
$dir = opendir($this->cache_dir);
|
$dir = opendir($this->cache_dir);
|
||||||
while ($entry = readdir($dir))
|
while ($entry = readdir($dir))
|
||||||
{
|
{
|
||||||
if ($entry{0} == '.')
|
if ($entry{0} == '.' || is_dir($this->cache_dir . $entry))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!$expire_time || time() - $expire_time >= filemtime($this->cache_dir . $entry))
|
if (time() - $expire_time >= filemtime($this->cache_dir . $entry))
|
||||||
{
|
{
|
||||||
unlink($this->cache_dir . $entry);
|
unlink($this->cache_dir . $entry);
|
||||||
}
|
}
|
||||||
|
@ -67,6 +100,11 @@ class acm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get($varname, $expire_time = 0)
|
||||||
|
{
|
||||||
|
return ($this->exists($varname, $expire_time)) ? $this->vars[$varname] : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
function put($varname, $var)
|
function put($varname, $var)
|
||||||
{
|
{
|
||||||
$this->vars[$varname] = $var;
|
$this->vars[$varname] = $var;
|
||||||
|
@ -84,16 +122,11 @@ class acm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($varname, $expire_time = 0)
|
|
||||||
{
|
|
||||||
return ($this->exists($varname, $expire_time)) ? $this->vars[$varname] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function exists($varname, $expire_time = 0)
|
function exists($varname, $expire_time = 0)
|
||||||
{
|
{
|
||||||
if (!is_array($this->vars))
|
if (!is_array($this->vars))
|
||||||
{
|
{
|
||||||
$this->load_cache();
|
$this->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($expire_time > 0)
|
if ($expire_time > 0)
|
||||||
|
@ -108,33 +141,6 @@ class acm
|
||||||
return isset($this->vars[$varname]);
|
return isset($this->vars[$varname]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function load_cache()
|
|
||||||
{
|
|
||||||
global $phpEx;
|
|
||||||
|
|
||||||
$this->vars = array();
|
|
||||||
@include($this->cache_dir . 'global.' . $phpEx);
|
|
||||||
}
|
|
||||||
|
|
||||||
function save_cache()
|
|
||||||
{
|
|
||||||
if (!$this->modified)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
global $phpEx;
|
|
||||||
$file = '<?php $this->vars=' . $this->format_array($this->vars) . ";\n\$this->vars_ts=" . $this->format_array($this->vars_ts) . ' ?>';
|
|
||||||
|
|
||||||
if ($fp = @fopen($this->cache_dir . 'global.' . $phpEx, 'wb'))
|
|
||||||
{
|
|
||||||
@flock($fp, LOCK_EX);
|
|
||||||
fwrite($fp, $file);
|
|
||||||
@flock($fp, LOCK_UN);
|
|
||||||
fclose($fp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function format_array($array)
|
function format_array($array)
|
||||||
{
|
{
|
||||||
$lines = array();
|
$lines = array();
|
||||||
|
@ -163,24 +169,23 @@ class acm
|
||||||
function sql_load($query)
|
function sql_load($query)
|
||||||
{
|
{
|
||||||
global $db, $phpEx;
|
global $db, $phpEx;
|
||||||
if (!file_exists($this->cache_dir . md5($query) . '.' . $phpEx))
|
@include($this->cache_dir . md5($query) . '.' . $phpEx);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
include($this->cache_dir . md5($query) . '.' . $phpEx);
|
if (!isset($rowset))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
$query_id = 'Cache id #' . count($this->sql_rowset);
|
$query_id = 'Cache id #' . count($this->sql_rowset);
|
||||||
$this->sql_rowset[$query_id] = $rowset;
|
$this->sql_rowset[$query_id] = $rowset;
|
||||||
$db->query_result = $query_id;
|
$db->query_result = $query_id;
|
||||||
|
return TRUE;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sql_save($query, $result)
|
function sql_save($query, $result)
|
||||||
{
|
{
|
||||||
global $db, $phpEx;
|
global $db, $phpEx;
|
||||||
if (@$fp = fopen($this->cache_dir . md5($query) . '.' . $phpEx, 'wb'))
|
if ($fp = @fopen($this->cache_dir . md5($query) . '.' . $phpEx, 'wb'))
|
||||||
{
|
{
|
||||||
@flock($fp, LOCK_EX);
|
@flock($fp, LOCK_EX);
|
||||||
|
|
||||||
|
|
|
@ -741,7 +741,7 @@ function redirect($url)
|
||||||
}
|
}
|
||||||
if (isset($cache))
|
if (isset($cache))
|
||||||
{
|
{
|
||||||
$cache->save_cache();
|
$cache->unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server_protocol = ($config['cookie_secure']) ? 'https://' : 'http://';
|
$server_protocol = ($config['cookie_secure']) ? 'https://' : 'http://';
|
||||||
|
|
|
@ -22,6 +22,12 @@
|
||||||
// Close our DB connection.
|
// Close our DB connection.
|
||||||
$db->sql_close();
|
$db->sql_close();
|
||||||
|
|
||||||
|
// Unload cache
|
||||||
|
if (!empty($cache))
|
||||||
|
{
|
||||||
|
$cache->unload();
|
||||||
|
}
|
||||||
|
|
||||||
// Output page creation time
|
// Output page creation time
|
||||||
if (defined('DEBUG'))
|
if (defined('DEBUG'))
|
||||||
{
|
{
|
||||||
|
@ -52,10 +58,6 @@ $template->assign_vars(array(
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
if (!empty($cache))
|
|
||||||
{
|
|
||||||
$cache->save_cache();
|
|
||||||
}
|
|
||||||
$template->display('body');
|
$template->display('body');
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
Loading…
Add table
Reference in a new issue