Re: Re: Function Cache

From: Date: Mon, 11 Dec 2000 11:37:50 +0000
Subject: Re: Re: Function Cache
References: 1 2 3 4 5 6  Groups: php.dev php.pear 
Request: Send a blank email to php-dev+get-40813@lists.php.net to get a copy of this message
Kristian Köhntopp wrote: > > "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. Ahem. I was not suggesting to implement this in PHP, but in C. Yuck. :-) - Stig

« previous php.dev (#40813) next »