PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.comp.lang.php > detecting a function call
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
detecting a function call

Réponse
 
LinkBack Outils de la discussion
Vieux 10/08/2007, 11h52   #1
philm
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut detecting a function call

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.

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

... in hope
PhilM


  Réponse avec citation
Vieux 10/08/2007, 14h30   #2
ZeldorBlat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: detecting a function call

On Aug 10, 6:52 am, "philm" <gate...@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.
>
> Other alternative I suppose, is to look at building in caching in each
> function...
>
> .. in hope
> PhilM


The second way is the way to do it. For instance:

funciton getFoo() {
//try to get foo from the cache
$foo = Cache::fetch('foo');

if($foo == false) {
$foo = ... //code to get foo from the database.
Cache::write('foo', $foo); //put foo in the cache
}

return $foo;
}

  Réponse avec citation
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
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h31.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08668 seconds with 11 queries