mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- bugfix/improvement in 3.1.22-dev cache locking did not work as expected
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
===== 3.1.22-dev ===== (xx.xx.2015)
|
===== 3.1.22-dev ===== (xx.xx.2015)
|
||||||
06.05.2015
|
06.05.2015
|
||||||
- bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates
|
- bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates
|
||||||
|
- bugfix/improvement in 3.1.22-dev cache locking did not work as expected
|
||||||
|
|
||||||
05.05.2015
|
05.05.2015
|
||||||
- optimization on cache update when main template is modified
|
- optimization on cache update when main template is modified
|
||||||
|
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.22-dev/27';
|
const SMARTY_VERSION = '3.1.22-dev/28';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -61,7 +61,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
|||||||
$cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock';
|
$cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock';
|
||||||
}
|
}
|
||||||
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
|
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
|
||||||
$cached->exists = is_file($cached->filepath);
|
$cached->timestamp = $cached->exists = is_file($cached->filepath);
|
||||||
if ($cached->exists) {
|
if ($cached->exists) {
|
||||||
$cached->timestamp = filemtime($cached->filepath);
|
$cached->timestamp = filemtime($cached->filepath);
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
|||||||
$obj = new Smarty_Internal_Write_File();
|
$obj = new Smarty_Internal_Write_File();
|
||||||
if ($obj->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
|
if ($obj->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
|
||||||
$cached = $_template->cached;
|
$cached = $_template->cached;
|
||||||
$cached->timestamp = $cached->exists = is_file( $cached->filepath);
|
$cached->timestamp = $cached->exists = is_file($cached->filepath);
|
||||||
if ($cached->exists) {
|
if ($cached->exists) {
|
||||||
$cached->timestamp = filemtime($cached->filepath);
|
$cached->timestamp = filemtime($cached->filepath);
|
||||||
return true;
|
return true;
|
||||||
|
@@ -603,7 +603,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
} else {
|
} else {
|
||||||
// file and php types can be checked without loading the respective resource handlers
|
// file and php types can be checked without loading the respective resource handlers
|
||||||
$mtime = is_file($_file_to_check[0]) ? @filemtime($_file_to_check[0]) : false;
|
$mtime = is_file($_file_to_check[0]) ? @filemtime($_file_to_check[0]) : false;
|
||||||
}
|
}
|
||||||
} elseif ($_file_to_check[2] == 'string') {
|
} elseif ($_file_to_check[2] == 'string') {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -56,17 +56,18 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
||||||
{
|
{
|
||||||
if ($template === null && $this instanceof $this->template_class) {
|
if ($template === null && $this instanceof $this->template_class) {
|
||||||
return $this->cached->valid;
|
$template = $this;
|
||||||
}
|
} else {
|
||||||
if (!($template instanceof $this->template_class)) {
|
if (!($template instanceof $this->template_class)) {
|
||||||
if ($parent === null) {
|
if ($parent === null) {
|
||||||
$parent = $this;
|
$parent = $this;
|
||||||
|
}
|
||||||
|
$smarty = isset($this->smarty) ? $this->smarty : $this;
|
||||||
|
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
|
||||||
}
|
}
|
||||||
$smarty = isset($this->smarty) ? $this->smarty : $this;
|
|
||||||
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
|
|
||||||
}
|
}
|
||||||
// return cache status of template
|
// return cache status of template
|
||||||
return $template->cached->valid;
|
return $template->cached->isCached($template);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,7 +121,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* @param boolean $cacheable if true (default) this fuction is cachable
|
* @param boolean $cacheable if true (default) this fuction is cachable
|
||||||
* @param array $cache_attr caching attributes if any
|
* @param array $cache_attr caching attributes if any
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
* @throws SmartyException when the plugin tag is invalid
|
* @throws SmartyException when the plugin tag is invalid
|
||||||
*/
|
*/
|
||||||
public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
|
public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
|
||||||
@@ -143,7 +145,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* @param string $type of plugin
|
* @param string $type of plugin
|
||||||
* @param string $tag name of plugin
|
* @param string $tag name of plugin
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function unregisterPlugin($type, $tag)
|
public function unregisterPlugin($type, $tag)
|
||||||
{
|
{
|
||||||
@@ -159,9 +162,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* Registers a resource to fetch a template
|
* Registers a resource to fetch a template
|
||||||
*
|
*
|
||||||
* @param string $type name of resource type
|
* @param string $type name of resource type
|
||||||
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)
|
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource
|
||||||
|
* (deprecated)
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function registerResource($type, $callback)
|
public function registerResource($type, $callback)
|
||||||
{
|
{
|
||||||
@@ -176,7 +181,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
*
|
*
|
||||||
* @param string $type name of resource type
|
* @param string $type name of resource type
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function unregisterResource($type)
|
public function unregisterResource($type)
|
||||||
{
|
{
|
||||||
@@ -194,7 +200,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* @param string $type name of cache resource type
|
* @param string $type name of cache resource type
|
||||||
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
|
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function registerCacheResource($type, Smarty_CacheResource $callback)
|
public function registerCacheResource($type, Smarty_CacheResource $callback)
|
||||||
{
|
{
|
||||||
@@ -209,7 +216,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
*
|
*
|
||||||
* @param string $type name of cache resource type
|
* @param string $type name of cache resource type
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function unregisterCacheResource($type)
|
public function unregisterCacheResource($type)
|
||||||
{
|
{
|
||||||
@@ -231,7 +239,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* @param array $block_methods list of block-methods
|
* @param array $block_methods list of block-methods
|
||||||
*
|
*
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
||||||
{
|
{
|
||||||
@@ -285,7 +294,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
*
|
*
|
||||||
* @param string $name object name
|
* @param string $name object name
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function unregisterObject($name)
|
public function unregisterObject($name)
|
||||||
{
|
{
|
||||||
@@ -304,7 +314,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* @param string $class_impl the referenced PHP class to register
|
* @param string $class_impl the referenced PHP class to register
|
||||||
*
|
*
|
||||||
* @throws SmartyException
|
* @throws SmartyException
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function registerClass($class_name, $class_impl)
|
public function registerClass($class_name, $class_impl)
|
||||||
{
|
{
|
||||||
@@ -324,7 +335,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
*
|
*
|
||||||
* @param callable $callback class/method name
|
* @param callable $callback class/method name
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
* @throws SmartyException if $callback is not callable
|
* @throws SmartyException if $callback is not callable
|
||||||
*/
|
*/
|
||||||
public function registerDefaultPluginHandler($callback)
|
public function registerDefaultPluginHandler($callback)
|
||||||
@@ -344,7 +356,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
*
|
*
|
||||||
* @param callable $callback class/method name
|
* @param callable $callback class/method name
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
* @throws SmartyException if $callback is not callable
|
* @throws SmartyException if $callback is not callable
|
||||||
*/
|
*/
|
||||||
public function registerDefaultTemplateHandler($callback)
|
public function registerDefaultTemplateHandler($callback)
|
||||||
@@ -358,7 +371,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
*
|
*
|
||||||
* @param callable $callback class/method name
|
* @param callable $callback class/method name
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
* @throws SmartyException if $callback is not callable
|
* @throws SmartyException if $callback is not callable
|
||||||
*/
|
*/
|
||||||
public function registerDefaultConfigHandler($callback)
|
public function registerDefaultConfigHandler($callback)
|
||||||
@@ -373,7 +387,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param callback $callback
|
* @param callback $callback
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function registerFilter($type, $callback)
|
public function registerFilter($type, $callback)
|
||||||
{
|
{
|
||||||
@@ -389,7 +404,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param callback $callback
|
* @param callback $callback
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function unregisterFilter($type, $callback)
|
public function unregisterFilter($type, $callback)
|
||||||
{
|
{
|
||||||
@@ -453,7 +469,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
|||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param string $name filter name
|
* @param string $name filter name
|
||||||
*
|
*
|
||||||
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
|
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
|
||||||
|
* Smarty_Internal_Template) instance for chaining
|
||||||
*/
|
*/
|
||||||
public function unloadFilter($type, $name)
|
public function unloadFilter($type, $name)
|
||||||
{
|
{
|
||||||
|
@@ -129,10 +129,17 @@ class Smarty_Template_Cached
|
|||||||
return $cached;
|
return $cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if cache is valid, lock cache if required
|
||||||
|
*
|
||||||
|
* @param \Smarty_Internal_Template $_template
|
||||||
|
* @param bool $lock keep cache locked
|
||||||
|
*
|
||||||
|
* @return bool flag true if cache is valid
|
||||||
|
*/
|
||||||
public function isCached(Smarty_Internal_Template $_template, $lock = false)
|
public function isCached(Smarty_Internal_Template $_template, $lock = false)
|
||||||
{
|
{
|
||||||
if ($this->valid !== null) {
|
if ($this->valid !== null) {
|
||||||
return $this->valid;
|
return $this->valid;
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -175,7 +182,7 @@ class Smarty_Template_Cached
|
|||||||
if ($_template->smarty->cache_locking && !$lock) {
|
if ($_template->smarty->cache_locking && !$lock) {
|
||||||
$this->handler->releaseLock($_template->smarty, $this);
|
$this->handler->releaseLock($_template->smarty, $this);
|
||||||
}
|
}
|
||||||
return $this->valid;
|
return $this->valid;
|
||||||
}
|
}
|
||||||
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && (time() > ($_template->cached->timestamp + $_template->properties['cache_lifetime']))) {
|
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && (time() > ($_template->cached->timestamp + $_template->properties['cache_lifetime']))) {
|
||||||
$this->valid = false;
|
$this->valid = false;
|
||||||
|
Reference in New Issue
Block a user