cvs: smarty / NEWS Smarty.class.php /docs programmers.sgml
| From: | Monte Ohrt | Date: | Mon, 15 Apr 2002 17:28:51 +0000 |
| Subject: | cvs: smarty / NEWS Smarty.class.php /docs programmers.sgml | ||
| Groups: | php.smarty.cvs | ||
| Request: | Send a blank email to php-smarty-cvs+get-60@lists.php.net to get a copy of this message | ||
mohrt Mon Apr 15 13:28:51 2002 EDT
Modified files:
/smarty NEWS Smarty.class.php
/smarty/docs programmers.sgml
Log:
update caching documentation
Index: smarty/NEWS
diff -u smarty/NEWS:1.190 smarty/NEWS:1.191
--- smarty/NEWS:1.190 Mon Apr 15 12:40:13 2002
+++ smarty/NEWS Mon Apr 15 13:28:46 2002
@@ -1,3 +1,5 @@
+ - added caching logic for expire times per cache file
+ (Norbert Rocher, Monte)
- fixed html_select_date when field separator is "/"
(Roberto Berto, Monte)
- added YYYY-MM-DD format support to html_select_date
Index: smarty/Smarty.class.php
diff -u smarty/Smarty.class.php:1.265 smarty/Smarty.class.php:1.266
--- smarty/Smarty.class.php:1.265 Mon Apr 15 12:39:16 2002
+++ smarty/Smarty.class.php Mon Apr 15 13:28:46 2002
@@ -13,7 +13,7 @@
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
@@ -92,7 +92,11 @@
var $force_compile = false; // force templates to compile every time,
// overrides cache settings. default false.
- var $caching = false; // enable caching. true/false default false.
+ var $caching = 0; // enable caching. can be one of 0/1/2.
+ // 0 = no caching
+ // 1 = use class cache_lifetime value
+ // 2 = use cache_lifetime in cache file
+ // default = 0.
var $cache_dir = 'cache'; // name of directory for template cache files
var $cache_lifetime = 3600; // number of seconds cached content will persist.
// 0 = always regenerate cache,
@@ -1414,7 +1418,14 @@
{
// put timestamp in cache header
$this->_cache_info['timestamp'] = time();
-
+ if ($this->cache_lifetime > -1){
+ // expiration set
+ $this->_cache_info['expires'] =
$this->_cache_info['timestamp'] + $this->cache_lifetime;
+ } else {
+ // cache will never expire
+ $this->_cache_info['expires'] = -1;
+ }
+
// prepend the cache header info into cache file
$results = serialize($this->_cache_info)."\n".$results;
@@ -1479,9 +1490,18 @@
$this->_cache_info = unserialize($cache_header);
- if ($this->cache_lifetime > -1 && (time() -
$this->_cache_info['timestamp'] > $this->cache_lifetime)) {
+ if ($this->caching == 2 && isset ($this->_cache_info['expires'])){
+ // caching by expiration time
+ if ($this->_cache_info['expires'] > -1 && (time() >
$this->_cache_info['expires'])) {
// cache expired, regenerate
return false;
+ }
+ } elseif ($this->caching == 1) {
+ // caching by lifetime
+ if ($this->cache_lifetime > -1 && (time() -
$this->_cache_info['timestamp'] > $this->cache_lifetime)) {
+ // cache expired, regenerate
+ return false;
+ }
}
if ($this->compile_check) {
Index: smarty/docs/programmers.sgml
diff -u smarty/docs/programmers.sgml:1.7 smarty/docs/programmers.sgml:1.8
--- smarty/docs/programmers.sgml:1.7 Fri Apr 12 10:46:29 2002
+++ smarty/docs/programmers.sgml Mon Apr 15 13:28:50 2002
@@ -173,14 +173,17 @@
<sect2 id="variable.caching">
<title>$caching</title>
<para>
- This tells Smarty whether or not to cache the output of the
- templates. By default this is set to false. If your templates
- generate redundant redundant content over and over again and
- again repeatedly, it is advisable to turn on caching. This will
- result in significant performance gains. You can also have
- multiple caches for the same template. See <link
- linkend="api.is.cached">is_cached</link> for details. This was
- added to Smarty 1.3.0.
+ This tells Smarty whether or not to cache the output of the templates.
+ By default this is set to 0, or disabled. If your templates generate
+ redundant redundant content, it is advisable to turn on caching. This
+ will result in significant performance gains. You can also have multiple
+ caches for the same template. A value of 1 or 2 enables caching. 1 tells
+ Smarty to use the current $cache_lifetime variable to determine if the
+ cache has expired. A value of 2 tells Smarty to use the cache_lifetime
+ value at the time the cache was generated. This way you can set the
+ cache_lifetime just before fetching the template to have granular
+ control over when that particular cache expires. See also <link
+ linkend="api.is.cached">is_cached</link>.
</para>
<para>
If $compile_check is enabled, the cached content will be
@@ -217,14 +220,15 @@
<sect2 id="variable.cache.lifetime">
<title>$cache_lifetime</title>
<para>
- This is the length of time in seconds that a template cache is
- valid. Once this time has expired, the cache will be
- regenerated. $caching must be set to "true" for this setting to
- work. You can also force the cache to expire with <link
- linkend="api.clear.all.cache">clear_all_cache</link>. A setting
- of -1 will force the cache to never expire. A setting of 0 will cause
- the cache to always regenerate (which doesn't make much sense, you'd be
- better off setting caching=false.)
+ This is the length of time in seconds that a template cache is valid.
+ Once this time has expired, the cache will be regenerated. $caching must
+ be set to "true" for this setting to work. You can also force the cache
+ to expire with <link
+ linkend="api.clear.all.cache">clear_all_cache</link>. A setting of -1
+ will force the cache to never expire. A setting of 0 will cause the
+ cache to always regenerate (which doesn't make much sense, you'd be
+ better off setting caching=false.) If $caching = 2, then the cache
+ expiration time is saved along with the template.
</para>
</sect2>
<sect2 id="variable.cache.handler.func">