cvs: php4 /pear/Cache Function.php URL.php

From: Date: Tue, 03 Jul 2001 15:17:05 +0000
Subject: cvs: php4 /pear/Cache Function.php URL.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-199@lists.php.net to get a copy of this message
sbergmann Tue Jul 3 11:17:05 2001 EDT Modified files: /php4/pear/Cache Function.php URL.php Log: Some comment/whitespace changes. Index: php4/pear/Cache/Function.php diff -u php4/pear/Cache/Function.php:1.6 php4/pear/Cache/Function.php:1.7 --- php4/pear/Cache/Function.php:1.6 Sat Mar 3 14:17:20 2001 +++ php4/pear/Cache/Function.php Tue Jul 3 11:17:03 2001 @@ -8,21 +8,21 @@ * * Example: * -* require_once "Cache/Function.php"; +* require_once 'Cache/Function.php'; * -* $FUNCTION_CACHE_CONTAINER = "file"; +* $FUNCTION_CACHE_CONTAINER = 'file'; * $FUNCTION_CACHE_CONTAINER_OPTIONS = array( -* "cache_dir" => "/tmp/", -* "filename_prefix" => "cache_"); +* 'cache_dir' => '/tmp/', +* 'filename_prefix' => 'cache_'); * * function foo($string) * { -* print $string . "<br>"; +* print $string . '<br>'; * for($i=1;$i<10000000;$i++){} * return strrev($string); * } * -* print cached_function_call("foo", "test"); +* print cached_function_call('foo', 'test'); * * Note: * @@ -35,7 +35,7 @@ * @module Function_Cache * @modulegroup Function_Cache * @package Cache -* @version $Revision: 1.6 $ +* @version $Revision: 1.7 $ * @access public */ @@ -55,7 +55,7 @@ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: Function.php,v 1.6 2001/03/03 19:17:20 uw Exp $ +// $Id: Function.php,v 1.7 2001/07/03 15:17:03 sbergmann Exp $ require_once 'Cache.php'; @@ -65,14 +65,12 @@ * @return mixed $result * @access public */ -function cached_function_call() -{ +function cached_function_call() { global $FUNCTION_CACHE_CONTAINER, $FUNCTION_CACHE_CONTAINER_OPTIONS; static $cache; // create Cache object, if needed - if (!is_object($cache)) - { + if (!is_object($cache)) { $cache = new Cache($FUNCTION_CACHE_CONTAINER, $FUNCTION_CACHE_CONTAINER_OPTIONS); } @@ -85,25 +83,22 @@ // query cache $cached_object = $cache->get($id); - // cache hit - if ($cached_object != NULL) - { + if ($cached_object != NULL) { + // cache hit: return cached output and result + $output = $cached_object[0]; $result = $cached_object[1]; - } + + } else { + // cache miss: call function, store output and result in cache - // 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)); } Index: php4/pear/Cache/URL.php diff -u php4/pear/Cache/URL.php:1.2 php4/pear/Cache/URL.php:1.3 --- php4/pear/Cache/URL.php:1.2 Sun May 20 10:28:29 2001 +++ php4/pear/Cache/URL.php Tue Jul 3 11:17:03 2001 @@ -21,7 +21,7 @@ * @module URL_Cache * @modulegroup URL_Cache * @package Cache -* @version $Revision: 1.2 $ +* @version $Revision: 1.3 $ * @access public */ @@ -41,7 +41,7 @@ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: URL.php,v 1.2 2001/05/20 14:28:29 sbergmann Exp $ +// $Id: URL.php,v 1.3 2001/07/03 15:17:03 sbergmann Exp $ require_once 'Cache.php'; @@ -62,15 +62,15 @@ $cache = new Cache($URL_CACHE_CONTAINER, $URL_CACHE_CONTAINER_OPTIONS); } - // generate Cache ID + // generate cache id $id = md5($url); - // query Cache + // query cache $data = $cache->get($id); - // Cache miss: Retrieve document at given URL and store it + // cache miss: retrieve document from given URL and store it if ($data == NULL) { - $fp = @fopen($url, "r"); + $fp = @fopen($url, 'r'); if($fp) { $data = fread($fp, 65536);

« previous php.pear.cvs (#199) next »