Changeset 742

Show
Ignore:
Timestamp:
12/05/06 02:57:11 (2 years ago)
Author:
sven
Message:

very rudimentary memcached experiment

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/includes.php

    r630 r742  
    2121    *    HELPER LIBRARIES 
    2222    ****************************************************************************/ 
     23 
     24    // Load cache lib 
     25        require_once($CFG->dirroot.'lib/cache/lib.php'); 
    2326 
    2427    // Load datalib 
  • devel/lib/datalib.php

    r708 r742  
    4141 
    4242    if ($result) { 
     43        // elggcache_purge(); // TODO - should probably be here, given function can do anything, but very inefficient 
    4344        if ($feedback) { 
    4445            notify(__gettext('Success'), 'notifysuccess'); 
     
    196197 
    197198    $METATABLES = $db->Metatables(); 
     199    elggcache_purge(); 
    198200     
    199201    return $success; 
     
    222224                      $signed='unsigned', $default='0', $null='not null', $after='') { 
    223225    global $CFG, $db; 
     226     
     227    elggcache_cachepurgetype($table); 
    224228 
    225229    if (empty($oldfield) && !empty($field)) { //adding 
     
    435439 
    436440    $values = where_values_prepared($value1, $value2, $value3); 
    437  
     441     
    438442    return record_exists_sql('SELECT * FROM '. $CFG->prefix . $table .' '. $select .' LIMIT 1',$values); 
    439  
    440443} 
    441444 
     
    597600 
    598601    global $CFG; 
     602    $trycache = false; 
     603     
     604    //just cache things by primary key for now 
     605    if ($field1 == "ident" && $value1 == intval($value1) && empty($field2)  && empty($value2) && empty($field3) && empty($value3) && $fields == "*") { 
     606        $trycache = true; 
     607        $cacheval = elggcache_get($table, $field1 . "_" . intval($value1)); 
     608        if (!is_null($cacheval)) { 
     609            return $cacheval; 
     610        } else { 
     611             
     612        } 
     613    } 
    599614 
    600615    $select = where_clause_prepared($field1, $field2, $field3); 
     
    602617    $values = where_values_prepared($value1, $value2, $value3); 
    603618     
    604     return get_record_sql('SELECT '.$fields.' FROM '. $CFG->prefix . $table .' '. $select, $values); 
     619    $returnvalue = get_record_sql('SELECT '.$fields.' FROM '. $CFG->prefix . $table .' '. $select, $values); 
     620     
     621    if ($trycache) { 
     622        $setres = elggcache_set($table, $field1 . "_" . $value1, $returnvalue); 
     623    } 
     624     
     625    return $returnvalue; 
    605626} 
    606627 
     
    11661187    $select = where_clause_prepared($field1, $field2, $field3); 
    11671188    $values = where_values_prepared($newvalue, $value1, $value2, $value3); 
    1168  
     1189     
    11691190    $stmt = $db->Prepare('UPDATE '. $CFG->prefix . $table .' SET '. $newfield  .' = ? '. $select); 
    1170     return $db->Execute($stmt,$values); 
     1191    $returnvalue = $db->Execute($stmt,$values); 
     1192     
     1193    if ($field1 == "ident") { 
     1194         // updating by primary key 
     1195        elggcache_delete($table, $field1 . "_" . $value1); 
     1196    } else { 
     1197        // sledgehammer :( 
     1198        elggcache_cachepurgetype($table); 
     1199    } 
     1200     
     1201    return $returnvalue; 
    11711202} 
    11721203 
     
    11951226     
    11961227    $stmt = $db->Prepare('DELETE FROM '. $CFG->prefix . $table .' '. $select); 
    1197     return $db->Execute($stmt,$values); 
     1228    $returnvalue = $db->Execute($stmt,$values); 
     1229     
     1230    if ($field1 == "ident") { 
     1231         // updating by primary key 
     1232        elggcache_delete($table, $field1 . "_" . $value1); 
     1233    } else { 
     1234        // sledgehammer :( 
     1235        elggcache_cachepurgetype($table); 
     1236    } 
     1237     
     1238    return $returnvalue; 
    11981239} 
    11991240 
     
    12251266        $result = $db->Execute('DELETE FROM '. $CFG->prefix . $table .' '. $select); 
    12261267    } 
     1268     
     1269    elggcache_cachepurgetype($table); 
     1270     
    12271271    return $result; 
    12281272} 
     
    12691313        if ($nextval = (int)get_field_sql("SELECT NEXTVAL('{$CFG->prefix}{$table}_{$primarykey}_seq')")) { 
    12701314            $setfromseq = true; 
    1271             $dataobject->{$primarykey} = $nextval;             
     1315            $dataobject->{$primarykey} = $nextval; 
    12721316        }  
    12731317    } 
     
    14331477    $stmt = $db->Prepare('UPDATE '. $CFG->prefix . $table .' SET '. $update .' WHERE ident = \''. $dataobject->ident .'\''); 
    14341478    if ($rs = $db->Execute($stmt,$ddd)) { 
     1479        elggcache_delete($table, "ident_" . $dataobject->ident); 
    14351480        return true; 
    14361481    } else { 
  • devel/lib/setup.php

    r729 r742  
    1414 
    1515// set up perf. 
    16 init_performance_info();         
     16init_performance_info(); 
    1717 
    1818/// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others) 
  • devel/units/weblogs/weblogs_text_process.php

    r716 r742  
    1212        } 
    1313         
    14         //check for mismatched <>s and force escaping if necessary 
    15         $numlt = substr_count($run_result, "<"); 
    16         $numgt = substr_count($run_result, ">"); 
    17         if ($numlt != $numgt) { 
    18             $run_result = htmlspecialchars($run_result, ENT_COMPAT, 'utf-8'); 
    19         } 
    20          
    21         // Videos 
    22          
    23         $functionbody = <<< END 
     14         $cachekey = sha1($addrelnofollow . "_" . $run_result); 
     15         if($cached = elggcache_get("weblogs_text_process:weblogs", $cachekey)) { 
     16             $run_result = $cached; 
     17         } else { 
    2418             
    25             \$matches[1] = str_replace("&amp;","&",\$matches[1]); 
    26             return "<embed style=\"width:400px; height:326px;\" id=\"VideoPlayback\" type=\"application/x-shockwave-flash\" src=\"\$matches[1]\" />"; 
    2719             
     20             
     21             
     22            //check for mismatched <>s and force escaping if necessary 
     23            $numlt = substr_count($run_result, "<"); 
     24            $numgt = substr_count($run_result, ">"); 
     25            if ($numlt != $numgt) { 
     26                $run_result = htmlspecialchars($run_result, ENT_COMPAT, 'utf-8'); 
     27            } 
     28             
     29            // Videos 
     30             
     31            $functionbody = <<< END 
     32                 
     33                \$matches[1] = str_replace("&amp;","&",\$matches[1]); 
     34                return "<embed style=\"width:400px; height:326px;\" id=\"VideoPlayback\" type=\"application/x-shockwave-flash\" src=\"\$matches[1]\" />"; 
     35                 
    2836END; 
    29  
    30         // $run_result = preg_replace_callback("/\{\{video:([A-Za-z0-9\.\:\_\-\/\\?\=\&\+]+)\}\}/i",create_function('$matches',$functionbody),$run_result); 
    31         $run_result = preg_replace_callback("/\{\{video:(.+)\}\}/i",create_function('$matches',$functionbody),$run_result); 
    32          
    33          
    34         // URLs to links 
    35         $run_result = run("weblogs:html_activate_urls", $run_result); 
    36          
    37         // Remove the evil font tag 
    38         $run_result = preg_replace("/<font[^>]*>/i","",$run_result); 
    39         $run_result = preg_replace("/<\/font>/i","",$run_result); 
    40          
    41         // add rel="nofollow" to any links 
    42         if ($addrelnofollow) { 
    43             $run_result = preg_replace('/<a\s+([^>]*)\s+rel=/i', '<a $1 ', $run_result); 
    44             $run_result = preg_replace('/<a\s+/i', '<a rel="nofollow" ', $run_result); 
    45         } 
    46          
    47         // Text cutting 
    48         // Commented out for the moment as it seems to disproportionately increase 
    49         // memory usage / load 
    50          
    51         /* 
    52         global $individual; 
    53          
    54         if (!isset($individual) || $individual != 1) { 
    55             $run_result = preg_replace("/\{\{cut\}\}(.|\n)*(\{\{uncut\}\})?/","{{more}}",$run_result); 
    56         } else { 
    57             // $run_result = preg_replace("/\{\{cut\}\}/","",$run_result); 
    58             $run_result = str_replace("{{cut}}","",$run_result); 
    59             $run_result = str_replace("{{uncut}}","",$run_result); 
    60         } 
    61         */ 
     37     
     38            // $run_result = preg_replace_callback("/\{\{video:([A-Za-z0-9\.\:\_\-\/\\?\=\&\+]+)\}\}/i",create_function('$matches',$functionbody),$run_result); 
     39            $run_result = preg_replace_callback("/\{\{video:(.+)\}\}/i",create_function('$matches',$functionbody),$run_result); 
     40             
     41             
     42            // URLs to links 
     43            $run_result = run("weblogs:html_activate_urls", $run_result); 
     44             
     45            // Remove the evil font tag 
     46            $run_result = preg_replace("/<font[^>]*>/i","",$run_result); 
     47            $run_result = preg_replace("/<\/font>/i","",$run_result); 
     48             
     49            // add rel="nofollow" to any links 
     50            if ($addrelnofollow) { 
     51                $run_result = preg_replace('/<a\s+([^>]*)\s+rel=/i', '<a $1 ', $run_result); 
     52                $run_result = preg_replace('/<a\s+/i', '<a rel="nofollow" ', $run_result); 
     53            } 
     54             
     55            // Text cutting 
     56            // Commented out for the moment as it seems to disproportionately increase 
     57            // memory usage / load 
     58             
     59            /* 
     60            global $individual; 
     61             
     62            if (!isset($individual) || $individual != 1) { 
     63                $run_result = preg_replace("/\{\{cut\}\}(.|\n)*(\{\{uncut\}\})?/","{{more}}",$run_result); 
     64            } else { 
     65                // $run_result = preg_replace("/\{\{cut\}\}/","",$run_result); 
     66                $run_result = str_replace("{{cut}}","",$run_result); 
     67                $run_result = str_replace("{{uncut}}","",$run_result); 
     68            } 
     69            */ 
     70             
     71             $setresult = elggcache_set("weblogs_text_process:weblogs", $cachekey, $run_result); 
     72         } 
    6273    } 
    6374