From adc6091c4d002d3c29cada904bb1cd2d4b56b761 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Sun, 9 Nov 2014 10:20:06 +0100 Subject: [PATCH] update of cache resources for template function calls in nocache mode --- libs/sysplugins/smarty_cacheresource.php | 15 ++++++++++ .../smarty_cacheresource_custom.php | 28 +++++++++++++++++++ .../smarty_cacheresource_keyvaluestore.php | 23 +++++++++++++++ .../smarty_internal_cacheresource_file.php | 15 ++++++++++ 4 files changed, 81 insertions(+) diff --git a/libs/sysplugins/smarty_cacheresource.php b/libs/sysplugins/smarty_cacheresource.php index 0329295e..ac2df598 100644 --- a/libs/sysplugins/smarty_cacheresource.php +++ b/libs/sysplugins/smarty_cacheresource.php @@ -449,4 +449,19 @@ class Smarty_Template_Cached return false; } + + /** + * Read cache content from handler + * + * @param Smarty_Internal_Template $_template template object + * + * @return string content + */ + public function read(Smarty_Internal_Template $_template) + { + if (!$_template->source->recompiled) { + return $this->handler->readCachedContent($_template); + } + return false; + } } diff --git a/libs/sysplugins/smarty_cacheresource_custom.php b/libs/sysplugins/smarty_cacheresource_custom.php index a258b2de..14309fb4 100644 --- a/libs/sysplugins/smarty_cacheresource_custom.php +++ b/libs/sysplugins/smarty_cacheresource_custom.php @@ -169,6 +169,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 * diff --git a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php index a4b365a8..c1c0f3fe 100644 --- a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php +++ b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php @@ -126,6 +126,29 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource return $this->write(array($_template->cached->filepath => $content), $_template->properties['cache_lifetime']); } + /** + * 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) { + if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) { + return false; + } + } + if (isset($content)) { + return $content; + } + return false; + } + + /** * Empty cache * {@internal the $exp_time argument is ignored altogether }} diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index b8e99cc6..5354a03b 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -117,6 +117,21 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource return false; } + /** + * Read cached template from cache + * + * @param Smarty_Internal_Template $_template template object + * + * @return string content + */ + public function readCachedContent(Smarty_Internal_Template $_template) + { + if (is_file($_template->cached->filepath)) { + return file_get_contents($_template->cached->filepath); + } + return false; + } + /** * Empty cache *