diff options
author | Mario Vavti <mario@mariovavti.com> | 2015-12-06 20:12:05 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2015-12-06 20:12:05 +0100 |
commit | c23ce16cafb826c8bb4fe7aaf2a5525b29052b23 (patch) | |
tree | 2230b03cfa6b74f3898b57bee647bc6276fd5a53 /library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php | |
parent | 78a70fed2f7cf9a53e6e4fab516b00cece12fbf0 (diff) | |
download | volse-hubzilla-c23ce16cafb826c8bb4fe7aaf2a5525b29052b23.tar.gz volse-hubzilla-c23ce16cafb826c8bb4fe7aaf2a5525b29052b23.tar.bz2 volse-hubzilla-c23ce16cafb826c8bb4fe7aaf2a5525b29052b23.zip |
update smarty library - seems to bring some performance improvement
Diffstat (limited to 'library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php')
-rw-r--r-- | library/Smarty/libs/sysplugins/smarty_cacheresource_custom.php | 52 |
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); } } |