Re: Re: Function Cache
| From: | Kristian Köhntopp | Date: | Mon, 11 Dec 2000 10:11:52 +0000 |
| Subject: | Re: Re: Function Cache | ||
| References: | 1 2 3 4 5 | Groups: | php.dev php.pear |
| Request: | Send a blank email to php-dev+get-40802@lists.php.net to get a copy of this message | ||
"Stig S. Bakken" wrote:
> The way I see it, don't get the real payoff of autoloading
> until you can autoload the classes themselves.
class generic_proxy {
var $proxy_reference;
function generic_proxy(&$pr = "") {
if ($pr == "")
return;
$this->proxy_reference = $pr;
}
function set_proxy_reference(&$pr) {
$old_pr = $this->proxy_reference;
$this->proxy_reference = $pr;
return $old_pr;
}
function AUTOLOAD($function_name) {
$args = func_get_args();
$hash = md5($function_name . ":" . serialize($args));
if (!check_cache_hit($hash)) {
cache_lock($hash);
ob_start();
// call $this->proxy_reference's $function_name method
// passing $args as the arguments to that function
// and saving the result in $result
// save result in cache
$out = ob_get_contents();
ob_end_clean();
// save $out in cache
cache_unlock($hash);
}
echo cached_output($hash);
return cached_result($hash);
}
}
$o = new SomeClass;
$w = new generc_proxy(&$o); // $w is now proxy to $o.
// $w will execute some method in o,
// caching the result.
$w->some_method_in_o($arg1, $arg2);
This should work: $w should be able to stand in for any
class, as a generic result cache around any class.
Kristian
--
Kristian Köhntopp, NetUSE AG Siemenswall, D-24107 Kiel
Tel: +49 431 386 436 00, Fax: +49 431 386 435 99
Using PHP3? See our web development library at http://phplib.netuse.de/