Afficher un message
Vieux 10/08/2007, 14h33   #3
Rik
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: detecting a function call

On Fri, 10 Aug 2007 12:52:59 +0200, philm <gates.w@microsoft.com> wrote:

> Asking for direction if possible.
>
> What I would like to be able to do is detect when particular functions
> are
> called, so as to be able to set up a results cache, and use that instead
> of
> continual db calls and processing.


At runtime? Just using flags I suppose.. Might be worth your while to
build an (singleton?) object out of several functions.

> Other alternative I suppose, is to look at building in caching in each
> function...


A variation of:

function foo($param){
static $results = array();
if(isset($results[$param])) return $results[$param];
//..
//actual processing, captured in $return;
//..
$results[$param] = $return;
return $return;
}


Or possibly, a wrapper function (be very aware of unserializable arguments
though):

function cache_results($function, $args = array()){
static $cache = array();
$checkargs = serialize($args);
if(isset($cache[$function][$checkargs])) return
$cache[$function][$checkargs];
$return = call_user_func_array($function,$args);
$cache[$function][$checkargs] = $return;
return $return;
}
--
Rik Wasmus
  Réponse avec citation
 
Page generated in 0,05827 seconds with 9 queries