sbergmann               Thu Mar  1 23:52:56 2001 EDT

  Added files:                 
    /php4/pear/Cache    Function.php 

  Modified files:              
    /php4/pear  Makefile.in 
  Log:
  Added experimental version of Cache_Function module.
  
Index: php4/pear/Makefile.in
diff -u php4/pear/Makefile.in:1.71 php4/pear/Makefile.in:1.72
--- php4/pear/Makefile.in:1.71  Thu Mar  1 11:22:25 2001
+++ php4/pear/Makefile.in       Thu Mar  1 23:52:56 2001
@@ -36,6 +36,7 @@
        Benchmark/Timer.php \
        Cache.php \
        Cache/Container.php \
+       Cache/Function.php \
        Cache/Graphics.php \
        Cache/Output.php \
        Cache/Container/db.php \

Index: php4/pear/Cache/Function.php
+++ php4/pear/Cache/Function.php
<?php
// +----------------------------------------------------------------------+
// | PHP version 4.0                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group             |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Sebastian Bergmann <[EMAIL PROTECTED]>               |
// +----------------------------------------------------------------------+
//
// $Id: Function.php,v 1.1 2001/03/02 07:52:56 sbergmann Exp $

require_once 'Cache.php';

function cached_function_call()
{
    static $cache;

    // create Cache object, if needed
    if (!is_object($cache))
    {
        $cache = new Cache(CACHE_CONTAINER, CACHE_CONTAINER_OPTIONS)
    }

    // get arguments
    $arguments = func_get_args();

    // generate cache id
    $id = md5(serialize($arguments));

    // query cache
    $cached_object = $cache->get($id);

    // cache hit
    if ($cached_object != NULL)
    {
        $output = $cached_object[0];
        $result = $cached_object[1];
    }

    // cache miss
    else
    {
        $function_name = array_shift($arguments);

        // call function, save output and result
        ob_start();
        $result = call_user_func_array($function_name, $arguments);
        $output = ob_get_contents();
        ob_end_clean();

        // store output and result of function call in cache
        $cache->save($id, array($output, $result));
    }

    print $output;
    return $result;
}
?>


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to