Changeset 1377

Show
Ignore:
Timestamp:
12/05/07 22:39:10 (1 year ago)
Author:
rho
Message:

fixed #189, cache run code for development environments

Signed-off: Rolando Espinoza La fuente <rho@prosoftpeople.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/units/engine/library.php

    r1093 r1377  
    2828            global $messages; 
    2929            global $data; 
     30            global $CFG; 
    3031             
    3132            global $run_context; 
     33 
     34            static $code_cache; 
     35            static $use_cache; 
     36 
     37            if (!isset($use_cache)) $use_cache = ($CFG->debug > 7) ? false : true; 
     38            if ($use_cache && !isset($code_cache)) $code_cache = array(); 
     39            //$code_cache=null; //turn off cache 
    3240             
    3341            $run_result = false; 
     
    3846                    echo "<small>\{$context}</small>"; 
    3947                } 
    40                  
     48 
    4149                foreach($function[$context] as $include) { 
    42                     include($include); 
     50                    if (!is_readable($include)) { 
     51                        trigger_error(__FUNCTION__.": can not load elgg function $include", E_USER_ERROR); 
     52                    } else { 
     53                        if ($use_cache) { 
     54                            if (isset($code_cache[$context][$include])) { 
     55                                eval('?>'.$code_cache[$context][$include]); 
     56                                //echo "cache: run('$context')<br/>"; 
     57                            } else { 
     58                                $code = @file_get_contents($include); 
     59                                // run code 
     60                                eval('?>'.$code); 
     61 
     62                                if (!isset($code_cache[$context])) $code_cache[$context] = array(); 
     63                                // cache code 
     64                                $code_cache[$context][$include] = $code; 
     65                            } 
     66                        } else { 
     67                            include($include); 
     68                        } 
     69                    } 
    4370                } 
    4471