mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
fixed is_cache, make cache reading more efficient
This commit is contained in:
4
NEWS
4
NEWS
@@ -1,6 +1,8 @@
|
|||||||
|
- made cache reading process more efficient (Monte)
|
||||||
|
- fixed bug, is_cached() now supports new 1.4.6 caching behavior (Monte)
|
||||||
- update FAQ with mailing list Reply-To header FAQ (Monte)
|
- update FAQ with mailing list Reply-To header FAQ (Monte)
|
||||||
- supress error messages for fopen(), fix cache to regenerate if cache
|
- supress error messages for fopen(), fix cache to regenerate if cache
|
||||||
file is not available due to race condition (Monte)
|
file is not available (i.e. cluster race condition) (Monte)
|
||||||
- added index key example to QUICKSTART guide (Monte)
|
- added index key example to QUICKSTART guide (Monte)
|
||||||
|
|
||||||
Version 1.4.6
|
Version 1.4.6
|
||||||
|
@@ -442,8 +442,13 @@ class Smarty
|
|||||||
|
|
||||||
if (file_exists($cache_file) &&
|
if (file_exists($cache_file) &&
|
||||||
($this->cache_lifetime == 0 ||
|
($this->cache_lifetime == 0 ||
|
||||||
(time() - filemtime($cache_file) <= $this->cache_lifetime)))
|
(time() - filemtime($cache_file) <= $this->cache_lifetime))) {
|
||||||
|
if($this->compile_check) {
|
||||||
|
return $this->_read_cache_file($cache_file,$results);
|
||||||
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -803,7 +808,6 @@ function _generate_debug_output() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if security is on, make sure template comes from a $secure_dir
|
// if security is on, make sure template comes from a $secure_dir
|
||||||
|
|
||||||
if ($this->security && !$this->security_settings['INCLUDE_ANY']) {
|
if ($this->security && !$this->security_settings['INCLUDE_ANY']) {
|
||||||
$resource_is_secure = false;
|
$resource_is_secure = false;
|
||||||
foreach ($this->secure_dir as $curr_dir) {
|
foreach ($this->secure_dir as $curr_dir) {
|
||||||
@@ -835,7 +839,6 @@ function _generate_debug_output() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1065,17 +1068,41 @@ function _run_mod_handler()
|
|||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _read_file()
|
Function: _read_file()
|
||||||
Purpose: read in a file
|
Purpose: read in a file from line $start to line $end.
|
||||||
|
read the entire file if $start and $end are null
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function _read_file($filename)
|
function _read_file($filename,$start=null,$end=null)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (!($fd = @fopen($filename, 'r'))) {
|
if (!($fd = @fopen($filename, 'r'))) {
|
||||||
$this->_trigger_error_msg("problem reading '$filename.'");
|
$this->_trigger_error_msg("problem reading '$filename.'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
flock($fd, LOCK_SH);
|
flock($fd, LOCK_SH);
|
||||||
|
if($start == null && $end == null) {
|
||||||
|
// read the entire file
|
||||||
$contents = fread($fd, filesize($filename));
|
$contents = fread($fd, filesize($filename));
|
||||||
|
} else {
|
||||||
|
if( $start > 1 ) {
|
||||||
|
// skip the first lines before $start
|
||||||
|
for ($loop=1; $loop < $start; $loop++) {
|
||||||
|
fgets($fd,65536);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( $end == null ) {
|
||||||
|
// read the rest of the file
|
||||||
|
while(!feof($fd)) {
|
||||||
|
$contents .= fgets($fd,65536);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// read up to $end lines
|
||||||
|
for ($loop=$start; $loop <= $end; $loop++) {
|
||||||
|
$contents .= fgets($fd,65536);
|
||||||
|
if(feof($fd)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
||||||
@@ -1225,18 +1252,12 @@ function _run_mod_handler()
|
|||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function _read_cache_file($cache_file,&$results)
|
function _read_cache_file($cache_file,&$results)
|
||||||
{
|
{
|
||||||
$results = $this->_read_file($cache_file);
|
if( !($cache_header = $this->_read_file($cache_file,1,1) )) {
|
||||||
|
|
||||||
if(empty($results)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the files involved with this cache from the first line
|
if (substr($cache_header, 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
||||||
$contents = explode("\n", $results, 2);
|
$cache_info = unserialize(substr($cache_header, 24));
|
||||||
|
|
||||||
if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
|
||||||
$cache_info = unserialize(substr($contents[0], 24));
|
|
||||||
$results = $contents[1];
|
|
||||||
|
|
||||||
if ($this->compile_check) {
|
if ($this->compile_check) {
|
||||||
$cache_filemtime = filemtime($cache_file);
|
$cache_filemtime = filemtime($cache_file);
|
||||||
@@ -1259,7 +1280,12 @@ function _run_mod_handler()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$results = $this->_read_file($cache_file,2);
|
||||||
|
} else {
|
||||||
|
// no cache info header, pre Smarty 1.4.6 format
|
||||||
|
$results = $this->_read_file($cache_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -442,8 +442,13 @@ class Smarty
|
|||||||
|
|
||||||
if (file_exists($cache_file) &&
|
if (file_exists($cache_file) &&
|
||||||
($this->cache_lifetime == 0 ||
|
($this->cache_lifetime == 0 ||
|
||||||
(time() - filemtime($cache_file) <= $this->cache_lifetime)))
|
(time() - filemtime($cache_file) <= $this->cache_lifetime))) {
|
||||||
|
if($this->compile_check) {
|
||||||
|
return $this->_read_cache_file($cache_file,$results);
|
||||||
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -803,7 +808,6 @@ function _generate_debug_output() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if security is on, make sure template comes from a $secure_dir
|
// if security is on, make sure template comes from a $secure_dir
|
||||||
|
|
||||||
if ($this->security && !$this->security_settings['INCLUDE_ANY']) {
|
if ($this->security && !$this->security_settings['INCLUDE_ANY']) {
|
||||||
$resource_is_secure = false;
|
$resource_is_secure = false;
|
||||||
foreach ($this->secure_dir as $curr_dir) {
|
foreach ($this->secure_dir as $curr_dir) {
|
||||||
@@ -835,7 +839,6 @@ function _generate_debug_output() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1065,17 +1068,41 @@ function _run_mod_handler()
|
|||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _read_file()
|
Function: _read_file()
|
||||||
Purpose: read in a file
|
Purpose: read in a file from line $start to line $end.
|
||||||
|
read the entire file if $start and $end are null
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function _read_file($filename)
|
function _read_file($filename,$start=null,$end=null)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (!($fd = @fopen($filename, 'r'))) {
|
if (!($fd = @fopen($filename, 'r'))) {
|
||||||
$this->_trigger_error_msg("problem reading '$filename.'");
|
$this->_trigger_error_msg("problem reading '$filename.'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
flock($fd, LOCK_SH);
|
flock($fd, LOCK_SH);
|
||||||
|
if($start == null && $end == null) {
|
||||||
|
// read the entire file
|
||||||
$contents = fread($fd, filesize($filename));
|
$contents = fread($fd, filesize($filename));
|
||||||
|
} else {
|
||||||
|
if( $start > 1 ) {
|
||||||
|
// skip the first lines before $start
|
||||||
|
for ($loop=1; $loop < $start; $loop++) {
|
||||||
|
fgets($fd,65536);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( $end == null ) {
|
||||||
|
// read the rest of the file
|
||||||
|
while(!feof($fd)) {
|
||||||
|
$contents .= fgets($fd,65536);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// read up to $end lines
|
||||||
|
for ($loop=$start; $loop <= $end; $loop++) {
|
||||||
|
$contents .= fgets($fd,65536);
|
||||||
|
if(feof($fd)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
||||||
@@ -1225,18 +1252,12 @@ function _run_mod_handler()
|
|||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
function _read_cache_file($cache_file,&$results)
|
function _read_cache_file($cache_file,&$results)
|
||||||
{
|
{
|
||||||
$results = $this->_read_file($cache_file);
|
if( !($cache_header = $this->_read_file($cache_file,1,1) )) {
|
||||||
|
|
||||||
if(empty($results)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the files involved with this cache from the first line
|
if (substr($cache_header, 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
||||||
$contents = explode("\n", $results, 2);
|
$cache_info = unserialize(substr($cache_header, 24));
|
||||||
|
|
||||||
if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
|
|
||||||
$cache_info = unserialize(substr($contents[0], 24));
|
|
||||||
$results = $contents[1];
|
|
||||||
|
|
||||||
if ($this->compile_check) {
|
if ($this->compile_check) {
|
||||||
$cache_filemtime = filemtime($cache_file);
|
$cache_filemtime = filemtime($cache_file);
|
||||||
@@ -1259,7 +1280,12 @@ function _run_mod_handler()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$results = $this->_read_file($cache_file,2);
|
||||||
|
} else {
|
||||||
|
// no cache info header, pre Smarty 1.4.6 format
|
||||||
|
$results = $this->_read_file($cache_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user