update caching documentation

This commit is contained in:
mohrt
2002-04-15 17:28:50 +00:00
parent f31dd5fa86
commit 7912d0b3d0
4 changed files with 70 additions and 24 deletions

2
NEWS
View File

@@ -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

View File

@@ -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 @@ class Smarty
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,6 +1418,13 @@ function _run_insert_handler($args)
{
// 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 @@ function _run_insert_handler($args)
$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) {

View File

@@ -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">

View File

@@ -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 @@ class Smarty
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,6 +1418,13 @@ function _run_insert_handler($args)
{
// 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 @@ function _run_insert_handler($args)
$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) {