- optimization of smarty_cachereource_keyvaluestore.php code

This commit is contained in:
Uwe Tews
2015-06-15 23:39:42 +02:00
parent 3bb22560c0
commit ec383370cb
3 changed files with 9 additions and 12 deletions

View File

@@ -1,4 +1,7 @@
 ===== 3.1.25-dev===== (xx.xx.2015)  ===== 3.1.25-dev===== (xx.xx.2015)
15.06.2015
- optimization of smarty_cachereource_keyvaluestore.php code
14.06.2015 14.06.2015
- bugfix a relative sub template path could fail if template_dir path did contain /../ https://github.com/smarty-php/smarty/issues/50 - bugfix a relative sub template path could fail if template_dir path did contain /../ https://github.com/smarty-php/smarty/issues/50
- optimization rework of path normalization - optimization rework of path normalization

View File

@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.25-dev/8'; const SMARTY_VERSION = '3.1.25-dev/9';
/** /**
* define variable scopes * define variable scopes

View File

@@ -36,6 +36,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @var array * @var array
*/ */
protected $contents = array(); protected $contents = array();
/** /**
* cache for timestamps * cache for timestamps
* *
@@ -53,10 +54,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/ */
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template) public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{ {
$cached->filepath = $_template->source->uid $cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' . $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
. '#' . $this->sanitize($cached->source->resource)
. '#' . $this->sanitize($cached->cache_id)
. '#' . $this->sanitize($cached->compile_id);
$this->populateTimestamp($cached); $this->populateTimestamp($cached);
} }
@@ -136,7 +134,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
public function readCachedContent(Smarty_Internal_Template $_template) public function readCachedContent(Smarty_Internal_Template $_template)
{ {
$content = $_template->cached->content ? $_template->cached->content : null; $content = $_template->cached->content ? $_template->cached->content : null;
$timestamp = null; $timestamp = null;
if ($content === null) { if ($content === null) {
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) { if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) {
return false; return false;
@@ -148,7 +146,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
return false; return false;
} }
/** /**
* Empty cache * Empty cache
* {@internal the $exp_time argument is ignored altogether }} * {@internal the $exp_time argument is ignored altogether }}
@@ -298,11 +295,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/ */
protected function getMetaTimestamp(&$content) protected function getMetaTimestamp(&$content)
{ {
$s = unpack("N", $content[0] . $content[1] . $content[2] . $content[3]); extract(unpack('N1s/N1m/a*content', $content));
$m = unpack("N", $content[4] . $content[5] . $content[6] . $content[7]); return $s + ($m / 100000000);
$content = substr($content, 8);
return $s[1] + ($m[1] / 100000000);
} }
/** /**