/[drupal]/contributions/modules/memcache/memcache_admin/memcache_admin.module
ViewVC logotype

Contents of /contributions/modules/memcache/memcache_admin/memcache_admin.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Thu Oct 30 19:15:37 2008 UTC (12 months, 3 weeks ago) by jeremy
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +2 -2 lines
File MIME type: text/x-php
Bug #292346: properly invalidate cache_page when cache_clear_all() called.
1 <?php
2 // $Id: memcache_admin.module,v 1.4 2008/01/29 22:50:25 slantview Exp $
3
4 function memcache_admin_menu($may_cache) {
5 $items = array();
6
7 if ($may_cache) {
8 $items[] = array(
9 'path' => 'admin/settings/memcache',
10 'callback' => 'memcache_admin_stats',
11 'title' => t('Memcache'),
12 //'type' => MENU_LOCAL_TASK,
13 'access' => user_access('access memcache statistics'),
14 'description' => t("View the statistics for this site's memcache and generate new settings."),
15 );
16 }
17
18 else {
19 $memache_servers = variable_get('memcache_servers', array());
20 $clusters = array();
21 foreach($memache_servers as $server => $cluster) {
22 $clusters[$cluster]['servers'][] = $server;
23 $clusters[$cluster]['bin'] = _memcache_admin_get_bin_for_cluster($cluster);
24 }
25
26 $count = 0;
27 foreach($clusters as $cluster => $cluster_info) {
28 if ($cluster_info['bin']) {
29
30 $items[] = array(
31 'path' => 'admin/settings/memcache/' . $cluster,
32 'type' => MENU_LOCAL_TASK,
33 'callback' => 'memcache_admin_stats',
34 'callback arguments' => array($cluster),
35 'title' => $cluster,
36 'access' => user_access('access memcache statistics'),
37 'weight' => $count,
38 );
39
40 $count++;
41 }
42 }
43
44
45 if ($arg = arg(3)) {
46 $count = 0;
47 foreach(array('default', 'reset', 'malloc', 'maps', 'cachedump', 'slabs', 'items', 'sizes') as $type) {
48 $items[] = array(
49 'path' => 'admin/settings/memcache/' . $arg . '/' . $type,
50 'type' => $type == 'default' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
51 'callback' => 'memcache_admin_stats',
52 'callback arguments' => array($arg, $type),
53 'title' => $type,
54 'access' => user_access('access memcache statistics'),
55 'weight' => $count,
56 );
57
58 $count++;
59 }
60 }
61 }
62
63 return $items;
64 }
65
66 function memcache_admin_stats($cluster = NULL, $type = 'default') {
67 $bin = _memcache_admin_get_bin_for_cluster($cluster);
68 $output = t('Please select a cluster');
69
70 if ($bin) {
71 if ($type == 'default') {
72 $type = '';
73 }
74
75 $stats = dmemcache_stats($bin, $type);
76
77 if (is_array($stats) && count($stats)) {
78 $output = "";
79
80 foreach ($stats as $server => $values) {
81 if (is_array($values)) {
82 $output .= theme('memcache_admin_stats_table', $server, $values);
83 }
84
85 else {
86 drupal_set_message(t('Unable to connect to server: %server', array('%server' => $server)));
87 }
88 }
89 }
90
91 else {
92 $output = '';
93 drupal_set_message(t('There seem to be no stats for this bin...'));
94 }
95 }
96
97 return $output;
98 }
99
100
101
102 function theme_memcache_admin_stats_table($server, $stats) {
103 $rows = array();
104
105 foreach ($stats as $key => $value) {
106 if (is_array($value)) {
107 $rs = array();
108 foreach ($value as $k => $v) {
109 $rs[] = array($k, $v);
110 }
111 $rows[] = array($key, theme('table', array('',''), $rs));
112 }
113 else {
114 $rows[] = array($key, $value);
115 }
116 }
117
118 return theme('table', array(t('Property'), t('Value')), $rows, array(), $server);
119 }
120
121
122
123 function _memcache_admin_get_bin_for_cluster($cluster) {
124 static $cluster_map = array();
125
126 if (!isset($cluster_map[$cluster])) {
127 $memache_bins = variable_get('memcache_bins', array());
128 if ($mapping = array_search($cluster, $memache_bins)) {
129 $cluster_map[$cluster] = $mapping;
130 }
131 else {
132 $cluster_map[$cluster] = 'default';
133 }
134 }
135
136 return $cluster_map[$cluster];
137 }

  ViewVC Help
Powered by ViewVC 1.1.2