aboutsummaryrefslogtreecommitdiffstats
path: root/library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php')
-rw-r--r--library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php52
1 files changed, 40 insertions, 12 deletions
diff --git a/library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php b/library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php
index a258b2de7..f496c1523 100644
--- a/library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php
+++ b/library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php
@@ -84,8 +84,11 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
{
$_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w\|]+!', '_', $cached->compile_id) : null;
-
- $cached->filepath = sha1($cached->source->filepath . $_cache_id . $_compile_id);
+ $path = $cached->source->filepath . $_cache_id . $_compile_id;
+ $cached->filepath = sha1($path);
+ if ($_template->smarty->cache_locking) {
+ $cached->lock_id = sha1('lock.' . $path);
+ }
$this->populateTimestamp($cached);
}
@@ -170,6 +173,34 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
}
/**
+ * Read cached template from cache
+ *
+ * @param Smarty_Internal_Template $_template template object
+ *
+ * @return string content
+ */
+ public function readCachedContent(Smarty_Internal_Template $_template)
+ {
+ $content = $_template->cached->content ? $_template->cached->content : null;
+ $timestamp = null;
+ if ($content === null) {
+ $timestamp = null;
+ $this->fetch(
+ $_template->cached->filepath,
+ $_template->source->name,
+ $_template->cache_id,
+ $_template->compile_id,
+ $content,
+ $timestamp
+ );
+ }
+ if (isset($content)) {
+ return $content;
+ }
+ return false;
+ }
+
+ /**
* Empty cache
*
* @param Smarty $smarty Smarty object
@@ -238,15 +269,14 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
- $id = $cached->filepath;
+ $id = $cached->lock_id;
$name = $cached->source->name . '.lock';
- $mtime = $this->fetchTimestamp($id, $name, null, null);
+ $mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id);
if ($mtime === null) {
- $this->fetch($id, $name, null, null, $content, $mtime);
+ $this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime);
}
-
- return $mtime && time() - $mtime < $smarty->locking_timeout;
+ return $mtime && ($t = time()) - $mtime < $smarty->locking_timeout;
}
/**
@@ -260,10 +290,9 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = true;
-
- $id = $cached->filepath;
+ $id = $cached->lock_id;
$name = $cached->source->name . '.lock';
- $this->save($id, $name, null, null, $smarty->locking_timeout, '');
+ $this->save($id, $name, $cached->cache_id, $cached->compile_id, $smarty->locking_timeout, '');
}
/**
@@ -277,8 +306,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
{
$cached->is_locked = false;
-
$name = $cached->source->name . '.lock';
- $this->delete($name, null, null, null);
+ $this->delete($name, $cached->cache_id, $cached->compile_id, null);
}
}