Commit ceff8be1 authored by robertDouglass's avatar robertDouglass
Browse files

#134174 by lyricnz and robertDouglass: add get/set/hit statistics to the...

#134174 by lyricnz and robertDouglass: add get/set/hit statistics to the bottom of pages like devel module does with queries. Note that this marks the beginning of the rebuilding of memcache.module. All other functionality has been stripped for the time being.
parent eed6f563
<?php
// $ID$
global $memcache_statistics;
$memcache_statistics = array('get' => 0, 'set' => 0, 'hit' => 0);
/*
* A memcache API for Drupal.
*/
......@@ -20,6 +23,8 @@
* @return bool
*/
function dmemcache_set($key, $value, $exp = 0, $bin = 'cache') {
global $memcache_statistics;
$memcache_statistics['set']++;
if ($mc = dmemcache_object($bin)) {
$full_key = dmemcache_key($key, $bin);
if (!$mc->set($full_key, $value, TRUE, $exp)) {
......@@ -41,9 +46,14 @@ function dmemcache_set($key, $value, $exp = 0, $bin = 'cache') {
* @return The item which was originally saved or FALSE
*/
function dmemcache_get($key, $bin = 'cache') {
global $memcache_statistics;
$memcache_statistics['get']++;
if ($mc = dmemcache_object($bin)) {
$full_key = dmemcache_key($key, $bin);
$result = $mc->get($full_key);
if ($result) {
$memcache_statistics['hit']++;
}
return $result;
}
}
......
<?php
function memcache_taxonomy($op, $type, $object=NULL) {
if (is_null($object)) {
return;
function memcache_init() {
if (strstr($_SERVER['PHP_SELF'], 'update.php') || strstr($_GET['q'], 'autocomplete')) {
// update.php relies on standard error handler
}
$object = (array)$object;
else {
drupal_add_js('misc/jquery.js');
register_shutdown_function('memcache_shutdown');
}
}
switch ($type) {
case 'term':
$key = $object['tid'];
break;
case 'vocabulary':
$key = $object['vid'];
break;
/**
* See memcache_init() which registers this function as a shutdown function.
* Displays memcache stats in the footer.
*/
function memcache_shutdown() {
global $user, $memcache_statistics;
// we only know how to handle 'term' and 'vocabulary', so return otherwise.
default:
return;
}
switch ($op) {
case 'delete':
case 'update':
dmemcache_flush($key, 'taxonomy_get_tree');
dmemcache_delete($key, $type);
}
$output = '';
}
// Try not to break non html pages.
if (function_exists('drupal_get_headers')) {
$headers = drupal_get_headers();
if(strstr($headers, 'xml') || strstr($headers, 'javascript') || strstr($headers, 'plain')) {
return;
}
}
function memcache_nodeapi($node, $op) {
switch ($op) {
case 'insert':
case 'update':
case 'delete':
dmemcache_delete($node->nid, 'node');
if ($user->uid == 1) {
$stats = array();
foreach ($memcache_statistics as $stat => $val) {
$stats[] = "<strong>$stat:</strong> $val";
}
if (!empty($stats)) {
$output = theme('item_list', $stats);
// this makes sure all of the HTML is within the <body> even though this <script> is outside it
print '<script type="text/javascript">
$(document).ready(function() {
$("body").append("'. str_replace(array("\r", "\n", "<", ">", "&"),
array('\r', '\n', '\x3c', '\x3e', '\x26'),
addslashes($output)) .'");
});
</script>';
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment