Re: Function caching...
| From: | Zeev Suraski | Date: | Sat, 09 Dec 2000 00:04:54 +0000 |
| Subject: | Re: Function caching... | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-40619@lists.php.net to get a copy of this message | ||
Aha, I see. Interesting idea. It requires lots of thinking, I can't think of an easy way to implement it off hand without slowing down things considerably for the general case. There are complex ways though :)
It's fairly easy to implement that sort of stuff in userland though, I'll try to think if it's possible to do it in a generic way in userland tomorrow.
Zeev
At 23:20 8/12/2000, Ulf Wendel wrote:
Zeev Suraski wrote: I'm not exactly sure what you meant in the 'Cachable function' term. What would be cached? The status of the local variables? The output? If it's one of those two, then both of them are fairly easy to implement today (even though we can always think of ways to improve it, if you think it's necessary). If it's something else - please clarify. It would be nice to be able to cache the output and return value of a function. The goal is to cache calls to functions that have a long runtime. If a cached function gets called a second time with the same arguments the return value and output gets taken from the cache. The function will not be executed again. We do not want to cache functions with static variables or those that depend on global resources ($GLOBALS, DB, Files...), of course a cache could not manage these things. At 17:01 7/12/2000, Kristian Köhntopp wrote:-- Zeev Suraski <zeev@zend.com> CTO, Zend Technologies Ltd. http://www.zend.com/Based on discussions with Ulf Wendel and Sebastian Bergmann, I came up with the attached code to gather function results and output. This should actually be part of the language, as sessions are, and it should be made to work with objects as well. A PHP program should be able to mark a function as cacheable cacheable function blah($arg1, $arg2) { output_something(); return generate_result(); } and the result and output of the function should be cached, keyed by the serialization of the args. IfMaybe an example clearyfies what is wanted. If you implement the function call cache on the user side it's something like this. function cache_call_func() { // get arguments $arguments = func_get_args(); // check, if function call is cached if (isset($GLOBALS[ "cache" ][ $hash ])) { print $GLOBALS[ "cache"][ $hash ][ "output" ]; return $GLOBALS[ "cache"][ $hash ][ "return" ]; } // calculate hash for function call $hash = md5( serialize( $arguments ) ); ... // start output buffering ob_start(); $cache[ $hash ][ "return" ] = call_user_func_array( $func_name, $arguments ); // store function's output in cache $cache[ $hash ][ "output" ] = ob_get_contents(); // end output buffering ob_end_clean(); } Kris preferrs a slightly different code as in the example. He likes to save the cached return values and the output to disk. This makes the cache persistent between multiple invokations of a script. The API should be very much like the session API where the user can override the default handling (storage) methods. Ulf -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net