mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
- bugfix in $smarty->cache->clear() method. (do not cache template object)
This commit is contained in:
@@ -1,30 +1,30 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin CacheResource File
|
* Smarty Internal Plugin CacheResource File
|
||||||
*
|
*
|
||||||
* Implements the file system as resource for the HTML cache
|
* Implements the file system as resource for the HTML cache
|
||||||
* Version ussing nocache inserts
|
* Version ussing nocache inserts
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage Cacher
|
* @subpackage Cacher
|
||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class does contain all necessary methods for the HTML cache on file system
|
* This class does contain all necessary methods for the HTML cache on file system
|
||||||
*/
|
*/
|
||||||
class Smarty_Internal_CacheResource_File {
|
class Smarty_Internal_CacheResource_File {
|
||||||
function __construct($smarty)
|
function __construct($smarty)
|
||||||
{
|
{
|
||||||
$this->smarty = $smarty;
|
$this->smarty = $smarty;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the filepath of the cached template output
|
* Returns the filepath of the cached template output
|
||||||
*
|
*
|
||||||
* @param object $_template current template
|
* @param object $_template current template
|
||||||
* @return string the cache filepath
|
* @return string the cache filepath
|
||||||
*/
|
*/
|
||||||
public function getCachedFilepath($_template)
|
public function getCachedFilepath($_template)
|
||||||
{
|
{
|
||||||
$_source_file_path = str_replace(':', '.', $_template->getTemplateFilepath());
|
$_source_file_path = str_replace(':', '.', $_template->getTemplateFilepath());
|
||||||
@@ -57,11 +57,11 @@ class Smarty_Internal_CacheResource_File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the timpestamp of the cached template output
|
* Returns the timpestamp of the cached template output
|
||||||
*
|
*
|
||||||
* @param object $_template current template
|
* @param object $_template current template
|
||||||
* @return integer |booelan the template timestamp or false if the file does not exist
|
* @return integer |booelan the template timestamp or false if the file does not exist
|
||||||
*/
|
*/
|
||||||
public function getCachedTimestamp($_template)
|
public function getCachedTimestamp($_template)
|
||||||
{
|
{
|
||||||
// return @filemtime ($_template->getCachedFilepath());
|
// return @filemtime ($_template->getCachedFilepath());
|
||||||
@@ -69,11 +69,11 @@ class Smarty_Internal_CacheResource_File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cached template output
|
* Returns the cached template output
|
||||||
*
|
*
|
||||||
* @param object $_template current template
|
* @param object $_template current template
|
||||||
* @return string |booelan the template content or false if the file does not exist
|
* @return string |booelan the template content or false if the file does not exist
|
||||||
*/
|
*/
|
||||||
public function getCachedContents($_template)
|
public function getCachedContents($_template)
|
||||||
{
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
@@ -83,11 +83,11 @@ class Smarty_Internal_CacheResource_File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the rendered template output to cache file
|
* Writes the rendered template output to cache file
|
||||||
*
|
*
|
||||||
* @param object $_template current template
|
* @param object $_template current template
|
||||||
* @return boolean status
|
* @return boolean status
|
||||||
*/
|
*/
|
||||||
public function writeCachedContent($_template, $content)
|
public function writeCachedContent($_template, $content)
|
||||||
{
|
{
|
||||||
if (!$_template->resource_object->isEvaluated) {
|
if (!$_template->resource_object->isEvaluated) {
|
||||||
@@ -100,24 +100,24 @@ class Smarty_Internal_CacheResource_File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty cache folder
|
* Empty cache folder
|
||||||
*
|
*
|
||||||
* @param integer $exp_time expiration time
|
* @param integer $exp_time expiration time
|
||||||
* @return integer number of cache files deleted
|
* @return integer number of cache files deleted
|
||||||
*/
|
*/
|
||||||
public function clearAll($exp_time = null)
|
public function clearAll($exp_time = null)
|
||||||
{
|
{
|
||||||
return $this->clear(null, null, null, $exp_time);
|
return $this->clear(null, null, null, $exp_time);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Empty cache for a specific template
|
* Empty cache for a specific template
|
||||||
*
|
*
|
||||||
* @param string $resource_name template name
|
* @param string $resource_name template name
|
||||||
* @param string $cache_id cache id
|
* @param string $cache_id cache id
|
||||||
* @param string $compile_id compile id
|
* @param string $compile_id compile id
|
||||||
* @param integer $exp_time expiration time
|
* @param integer $exp_time expiration time
|
||||||
* @return integer number of cache files deleted
|
* @return integer number of cache files deleted
|
||||||
*/
|
*/
|
||||||
public function clear($resource_name, $cache_id, $compile_id, $exp_time)
|
public function clear($resource_name, $cache_id, $compile_id, $exp_time)
|
||||||
{
|
{
|
||||||
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
|
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
|
||||||
@@ -131,12 +131,14 @@ class Smarty_Internal_CacheResource_File {
|
|||||||
$_cache_id_parts_count = count($_cache_id_parts);
|
$_cache_id_parts_count = count($_cache_id_parts);
|
||||||
}
|
}
|
||||||
if (isset($resource_name)) {
|
if (isset($resource_name)) {
|
||||||
$_save_stat = $this->smarty->caching;
|
$_save_stat = $this->smarty->caching;
|
||||||
$this->smarty->caching = true;
|
$this->smarty->caching = true;
|
||||||
$tpl = $this->smarty->createTemplate($resource_name);
|
$tpl = new $this->smarty->template_class($resource_name, $this->smarty);
|
||||||
$this->smarty->caching = $_save_stat;
|
// remove from template cache
|
||||||
|
unset($this->smarty->template_objects[crc32($tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
|
||||||
|
$this->smarty->caching = $_save_stat;
|
||||||
if ($tpl->isExisting()) {
|
if ($tpl->isExisting()) {
|
||||||
$_resourcename_parts = basename(str_replace('^','/',$tpl->getCachedFilepath()));
|
$_resourcename_parts = basename(str_replace('^', '/', $tpl->getCachedFilepath()));
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -179,7 +181,7 @@ class Smarty_Internal_CacheResource_File {
|
|||||||
// expired ?
|
// expired ?
|
||||||
if (isset($exp_time) && time() - @filemtime($_file) < $exp_time) {
|
if (isset($exp_time) && time() - @filemtime($_file) < $exp_time) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$_count += @unlink((string) $_file) ? 1 : 0;
|
$_count += @unlink((string) $_file) ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user