Skip to content

Commit

Permalink
Merge branch "master" of github.com:humanmade/memcache-object-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
joehoyle committed Oct 14, 2014
2 parents 2382c53 + f969d0a commit 4c5b4ef
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class WP_Object_Cache {

var $cache = array();
var $mc = array();
var $stats = array();
var $stats = array( "get" => 0, "get_time" => 0, "add" => 0, "add_time" => 0, "delete" => 0, "delete_time" => 0, "set" => 0, "set_time" => 0 );
var $group_ops = array();

var $cache_enabled = true;
Expand All @@ -125,10 +125,14 @@ function add($id, $data, $group = 'default', $expire = 0) {

$mc =& $this->get_mc($group);
$expire = ($expire == 0) ? $this->default_expiration : $expire;

$time = microtime(true);
$result = $mc->add($key, $data, false, $expire);
$time_taken = microtime(true) - $time;

if ( false !== $result ) {
@ ++$this->stats['add'];
$this->stats['add_time'] += $time_taken;
$this->group_ops[$group][] = "add $id";
$this->cache[$key] = $data;
}
Expand Down Expand Up @@ -182,9 +186,12 @@ function delete($id, $group = 'default') {

$mc =& $this->get_mc($group);

$time = microtime(true);
$result = $mc->delete($key);
$time_taken = microtime(true) - $time;

@ ++$this->stats['delete'];
$this->stats['delete_time'] += $time_taken;
$this->group_ops[$group][] = "delete $id";

if ( false !== $result )
Expand Down Expand Up @@ -213,15 +220,21 @@ function get($id, $group = 'default', $force = false) {
} else if ( in_array($group, $this->no_mc_groups) ) {
$this->cache[$key] = $value = false;
} else {

$time = microtime(true);

$value = $mc->get($key);
if ( NULL === $value )
$value = false;

$time_taken = microtime(true) - $time;

$this->cache[$key] = $value;
@ ++$this->stats['get'];
$this->stats['get_time'] += $time_taken;
$this->group_ops[$group][] = "get $id";
}

@ ++$this->stats['get'];
$this->group_ops[$group][] = "get $id";

if ( 'checkthedatabaseplease' === $value ) {
unset( $this->cache[$key] );
$value = false;
Expand Down Expand Up @@ -304,13 +317,22 @@ function set($id, $data, $group = 'default', $expire = 0) {

$expire = ($expire == 0) ? $this->default_expiration : $expire;
$mc =& $this->get_mc($group);

$time = microtime(true);
$result = $mc->set($key, $data, false, $expire);
$time_taken = microtime(true) - $time;

@ ++$this->stats['set'];
$this->stats['set_time'] += $time_taken;
$this->group_ops[$group][] = "set $id";

return $result;
}

function switch_to_blog( $blog_id ) {
$blog_id = (int) $blog_id;
global $wpdb;
$table_prefix = $wpdb->prefix;
$this->blog_prefix = ( is_multisite() ? $blog_id : $table_prefix ) . ':';
}

Expand All @@ -331,6 +353,11 @@ function colorize_debug_line($line) {
function stats() {
echo "<p>\n";
foreach ( $this->stats as $stat => $n ) {

if ( ! $n ) {
continue;
}

echo "<strong>$stat</strong> $n";
echo "<br/>\n";
}
Expand Down

0 comments on commit 4c5b4ef

Please sign in to comment.