diff --git a/dmemcache.inc b/dmemcache.inc index cc32f3809afad981456c7faf421f7f57fd7763ac..5cc04e2eeee96a5434c7d5b416c0c6ba0634eb84 100644 --- a/dmemcache.inc +++ b/dmemcache.inc @@ -10,7 +10,7 @@ */ global $_memcache_statistics; -$_memcache_statistics = array('get' => array(), 'set' => array(), 'hit' => array()); +$_memcache_statistics = array(); /* * A memcache API for Drupal. @@ -35,10 +35,9 @@ $_memcache_statistics = array('get' => array(), 'set' => array(), 'hit' => array */ function dmemcache_set($key, $value, $exp = 0, $bin = 'cache', $mc = NULL) { global $_memcache_statistics; - $_memcache_statistics['set'][] = $key; - $_memcache_statistics['bins'][] = $bin; + $full_key = dmemcache_key($key, $bin); + $_memcache_statistics[] = array('set', $bin, $full_key, ''); if ($mc || ($mc = dmemcache_object($bin))) { - $full_key = dmemcache_key($key, $bin); if (class_exists('Memcached')) { return $mc->set($full_key, $value, $exp); } @@ -72,10 +71,9 @@ function dmemcache_set($key, $value, $exp = 0, $bin = 'cache', $mc = NULL) { */ function dmemcache_add($key, $value, $exp = 0, $bin = 'cache', $mc = NULL, $flag = FALSE) { global $_memcache_statistics; - $_memcache_statistics['add'][] = $key; - $_memcache_statistics['bins'][] = $bin; + $full_key = dmemcache_key($key, $bin); + $_memcache_statistics[] = array('add', $bin, $full_key, ''); if ($mc || ($mc = dmemcache_object($bin))) { - $full_key = dmemcache_key($key, $bin); if (class_exists('Memcached')) { return $mc->add($full_key, $value, $exp); } @@ -96,16 +94,18 @@ function dmemcache_add($key, $value, $exp = 0, $bin = 'cache', $mc = NULL, $flag */ function dmemcache_get($key, $bin = 'cache', $mc = NULL) { global $_memcache_statistics; - $_memcache_statistics['get'][] = $key; - $_memcache_statistics['bins'][] = $bin; + $full_key = dmemcache_key($key, $bin); + $statistics = array('get', $bin, $full_key); + $success = '0'; if ($mc || ($mc = dmemcache_object($bin))) { - $full_key = dmemcache_key($key, $bin); $result = $mc->get($full_key); if ($result) { - $_memcache_statistics['hit'][] = $key; - return $result; + $success = '1'; } } + $statistics[] = $success; + $_memcache_statistics[] = $statistics; + return $result; } /** @@ -115,19 +115,18 @@ function dmemcache_get($key, $bin = 'cache', $mc = NULL) { * @param $bin The bin in which the item was stored. * * @return The item which was originally saved or FALSE - * - * TODO: Record statistics w/ multi-get */ function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) { global $_memcache_statistics; - $_memcache_statistics['get'] = array_merge($_memcache_statistics['get'], $keys); - $_memcache_statistics['bins'][] = $bin; + $full_keys = array(); + $statistics = array(); + foreach ($keys as $key => $cid) { + $full_key = dmemcache_key($cid, $bin); + $statistics[$full_key] = array('getMulti', $bin, $full_key); + $full_keys[] = $full_key; + } $results = array(); if ($mc || ($mc = dmemcache_object($bin))) { - $full_keys = array(); - foreach ($keys as $key => $cid) { - $full_keys[] = dmemcache_key($cid, $bin); - } if (class_exists('Memcached')) { $results = $mc->getMulti($full_keys); } @@ -135,6 +134,10 @@ function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) { $results = $mc->get($full_keys); } } + foreach ($statistics as $key => $values) { + $values[] = isset($results[$key]) ? '1': '0'; + $_memcache_statistics[] = $values; + } return $results; } @@ -147,8 +150,10 @@ function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) { * @return Returns TRUE on success or FALSE on failure. */ function dmemcache_delete($key, $bin = 'cache', $mc = NULL) { + global $_memcache_statistics; + $full_key = dmemcache_key($key, $bin); + $_memcache_statistics[] = array('delete', $bin, $full_key, ''); if ($mc || ($mc = dmemcache_object($bin))) { - $full_key = dmemcache_key($key, $bin); return $mc->delete($full_key); } return FALSE; @@ -165,6 +170,8 @@ function dmemcache_delete($key, $bin = 'cache', $mc = NULL) { * @return Returns TRUE on success or FALSE on failure. */ function dmemcache_flush($bin = 'cache', $mc = NULL) { + global $_memcache_statistics; + $_memcache_statistics[] = array('flush', $bin, '', ''); if ($mc || ($mc = dmemcache_object($bin))) { return memcache_flush($mc); } diff --git a/memcache-lock.inc b/memcache-lock.inc index 5d252840668f0240c92e82d558d39af0257475a5..12944c5340357b90fa2976b21e2be4022cddfcdd 100644 --- a/memcache-lock.inc +++ b/memcache-lock.inc @@ -6,6 +6,8 @@ * See includes/lock.inc for documenation */ +require_once dirname(__FILE__) . '/dmemcache.inc'; + // Set up a define to make the code more readable, so we know we're setting a // value for our lock and not simply passing dmemcache a flag. define('LOCK_VALUE', TRUE); diff --git a/memcache_admin/memcache_admin.module b/memcache_admin/memcache_admin.module index 5e08bcba8a7ae77a43e05e46861f213072afe4f4..31b337dc7dbc20abc905080c014ee630d5df4d3b 100644 --- a/memcache_admin/memcache_admin.module +++ b/memcache_admin/memcache_admin.module @@ -239,14 +239,10 @@ function memcache_admin_shutdown() { } if (variable_get('show_memcache_statistics', TRUE) && function_exists('user_access') && user_access('access memcache statistics')) { - $stats = array(); - - foreach ($_memcache_statistics as $stat => $value) { - $items = array('items' => $value); - $stats[] = "$stat: ". theme('item_list', array('items' => $value)); - } - if (!empty($stats)) { - $output = theme('item_list', array('items' => $stats)); + if (!empty($_memcache_statistics)) { + $variables = array('header' => array(t('Operation'), t('Bin'), t('Key'), t('Hit')), + 'rows' => $_memcache_statistics); + $output = theme('table', $variables); // this makes sure all of the HTML is within the even though this