Date: 10/26/00
- Next message: Daniel Bondurant: "[phplib] iis, frames and page_close"
- Previous message: netbsd alpha: "Re: [phplib] the perm flag bits."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Per the GPL, here is an extension of the Template class I wrote for caching
pages created with the template object. Cached pages can be stored in any
path for any duration with any name.
Tom
<?
class c_Template extends Template {
/* for caching pages */
var $refreshCache = false;
var $cacheName = "";
var $cachePath = "/tmp/";
/* default = 15 min */
var $cacheTimeout = 900;
/**
* Override the ancestor function so we can save the parse result
*/
function pparse($target, $handle, $append = false) {
$str = $this->parse($target, $handle, $append);
// For caching
if ($this->refreshCache) error_log($str, 3, $this->cachePath .
$this->cacheName);
print $str;
return false;
}
/**
* set_cache ( array or string )
*
* Parameter: array or cache file name
*
* set_cache(array("name" => "cache file name",
* "path" => "cache file path",
* "timeout" => seconds before refresh));
*
* or set_cache("cache file name");
*/
function set_cache($cacheParms) {
if (is_array($cacheParms)) {
// Set name and the path to the cached file
$this->cacheName = $cacheParms["name"];
if ($cacheParms["path"]) $this->cachePath = $cacheParms["path"];
// Set timeout to 15 min. if not specified
if ($cacheParms["timeout"]) $this->cacheTimeout =
$cacheParms["timeout"];
} else {
$this->cacheName = $cacheParms;
}
if (!$this->cacheName) return false;
// Get the last modified time for the file
## lstat[9] = FILE_LASTUPDATE
$fileProps = lstat($this->cachePath . $this->cacheName);
// Set the refresh cache to true if our delta is too big
if ($this -> refreshCache = ((time() - $fileProps[9]) >
$this->cacheTimeout)) {
// Delete the cached file
<email protected>($this->cachePath . $this->cacheName);
} else {
// Use the cache
include ($this->cachePath . $this->cacheName);
die();
}
}
}
?>
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Share information about yourself, create your own public profile at
http://profiles.msn.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>
- Next message: Daniel Bondurant: "[phplib] iis, frames and page_close"
- Previous message: netbsd alpha: "Re: [phplib] the perm flag bits."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

