summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodneyrehm <rodneyrehm@localhost>2011-09-19 20:17:22 +0000
committerrodneyrehm <rodneyrehm@localhost>2011-09-19 20:17:22 +0000
commitc877da74de38808351558cf77ce8c05175bf8711 (patch)
tree7bb95f97f41cf01ea2857832d302e05a6b5469ae
parent8e6626fbca3d04898ba289cd521988e972899fa1 (diff)
downloadsmarty-c877da74de38808351558cf77ce8c05175bf8711.tar.gz
smarty-c877da74de38808351558cf77ce8c05175bf8711.tar.bz2
smarty-c877da74de38808351558cf77ce8c05175bf8711.zip
- bugfix regression in Smarty_CacheReource_KeyValueStore introduced by r4261
- added APC test - added read/write test to APC demo ('cause it ain't working on my machine!?)
-rw-r--r--change_log.txt3
-rw-r--r--demo/plugins/cacheresource.apc.php11
-rw-r--r--libs/sysplugins/smarty_cacheresource_keyvaluestore.php38
3 files changed, 33 insertions, 19 deletions
diff --git a/change_log.txt b/change_log.txt
index 3aa544ef..7e61b185 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -1,4 +1,7 @@
===== Smarty 3.1 trunk =====
+19.09.2011
+- bugfix regression in Smarty_CacheReource_KeyValueStore introduced by r4261
+
18.09.2011
- bugfix template caching did not care about file.tpl in different template_dir
- bugfix {include $file} was broken when merge_compiled_incluges = true
diff --git a/demo/plugins/cacheresource.apc.php b/demo/plugins/cacheresource.apc.php
index 40369e3a..5403f3bc 100644
--- a/demo/plugins/cacheresource.apc.php
+++ b/demo/plugins/cacheresource.apc.php
@@ -14,8 +14,15 @@ class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore {
public function __construct()
{
// test if APC is present
- if(!function_exists('apc_cache_info'))
- throw new Exception('APC Template Caching Error: APC is not installed');
+ if(!function_exists('apc_cache_info')) {
+ throw new Exception('APC Template Caching Error: APC is not installed');
+ }
+
+ apc_store(array('foo' => 'bar'));
+ $t = apc_fetch(array('foo'));
+ if (!$t || $t['foo'] != 'bar') {
+ throw new Exception('APC Template Caching Error: APC is not working properly');
+ }
}
/**
diff --git a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php
index 93abf4d7..6d2d3b83 100644
--- a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php
+++ b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php
@@ -69,7 +69,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
{
- if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content, $timestamp)) {
+ if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content, $timestamp, $cached->source->uid)) {
return;
}
$cached->content = $content;
@@ -92,7 +92,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
$content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) {
- if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp)) {
+ if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) {
return false;
}
}
@@ -153,23 +153,22 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
- $cid = $this->buildCachedFilepath($smarty,$resource_name, $cache_id, $compile_id);
+ $uid = $this->getTemplateUid($smarty, $resource_name, $cache_id, $compile_id);
+ $cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id);
$this->delete(array($cid));
- $this->invalidate($cid, $resource_name, $cache_id, $compile_id);
+ $this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
return -1;
}
-
/**
- * Get system filepath to cached file.
+ * Get template's unique ID
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
* @return string filepath of cache file
- * @uses sanitize() on $resource_name and $compile_id to avoid bad segments
*/
- protected function buildCachedFilepath(Smarty $smarty, $resource_name, $cache_id, $compile_id)
+ protected function getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id)
{
$uid = '';
if (isset($resource_name)) {
@@ -180,7 +179,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
// remove from template cache
unset($smarty->template_objects[sha1(join(DIRECTORY_SEPARATOR, $smarty->getTemplateDir()) . $tpl->template_resource . $tpl->cache_id . $tpl->compile_id)]);
}
- return $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id);
+ return $uid;
}
/**
@@ -208,16 +207,17 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
* @param string $compile_id compile id
* @param string $content cached content
* @param integer &$timestamp cached timestamp (epoch)
+ * @param string $resource_uid resource's uid
* @return boolean success
*/
- protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, &$timestamp = null)
+ protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, &$timestamp = null, $resource_uid = null)
{
$t = $this->read(array($cid));
$content = !empty($t[$cid]) ? $t[$cid] : null;
$timestamp = null;
if ($content && ($timestamp = $this->getMetaTimestamp($content))) {
- $invalidated = $this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id);
+ $invalidated = $this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid);
if ($invalidated > $timestamp) {
$timestamp = null;
$content = null;
@@ -262,9 +262,10 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
+ * @param string $resource_uid source's uid
* @return void
*/
- protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null)
+ protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
{
$now = microtime(true);
$key = null;
@@ -274,7 +275,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
}
// invalidate all caches by template
else if ($resource_name && !$cache_id && !$compile_id) {
- $key = 'IVK#TEMPLATE#' . $this->sanitize($resource_name);
+ $key = 'IVK#TEMPLATE#' . $resource_uid . '#' . $this->sanitize($resource_name);
}
// invalidate all caches by cache group
else if (!$resource_name && $cache_id && !$compile_id) {
@@ -298,18 +299,20 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
+ * @param string $resource_uid source's filepath
* @return float the microtime the CacheID was invalidated
*/
- protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null)
+ protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
{
// abort if there is no CacheID
if (false && !$cid) {
return 0;
}
// abort if there are no InvalidationKeys to check
- if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id))) {
+ if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id, $resource_uid))) {
return 0;
}
+
// there are no InValidationKeys
if (!($values = $this->read($_cid))) {
return 0;
@@ -328,15 +331,16 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource {
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
+ * @param string $resource_uid source's filepath
* @return array list of InvalidationKeys
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
*/
- protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null)
+ protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
{
$t = array('IVK#ALL');
$_name = $_compile = '#';
if ($resource_name) {
- $_name .= $this->sanitize($resource_name);
+ $_name .= $resource_uid . '#' . $this->sanitize($resource_name);
$t[] = 'IVK#TEMPLATE' . $_name;
}
if ($compile_id) {