Function caching...

From: Date: Thu, 07 Dec 2000 15:01:51 +0000
Subject: Function caching...
Groups: php.dev 
Request: Send a blank email to php-dev+get-40381@lists.php.net to get a copy of this message
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. If you oppose adding keywords to the language, you should be able to function blah($arg1, $arg2) { output_something(); return generate_result(); } cache_register("blah"); This is actually preferred to adding a keyword, because you could add an additional cache identifier (default: main) cache_register("blah", "blah_module"); In both cases, all calls to blah($x, $y) should be transparently cached. The cache mechanism should have an API similar to the session API which allows to provide user callbacks to actually create the cache in shared memory, in files, or in any other persistent store. That would be a string get_res_cache(string hash, string identifier); boolean set_res_cache(string hash, string value, string identifer); string get_out_cache(string hash, string identifier); boolean set_out_cache(string hash, string value, string identifer); Also, there should be boolean invalidate_cache(string identifier); to selectively invalidate the cache identified by identifier. What do you think about the proposal? Kristian PS: The attached example is deliberately uncacheable. Cacheable functions are not using global nor static and call only idempotent functions themselves. -- 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/

« previous php.dev (#40381) next »