diff --git a/memcache_storage.api.inc b/memcache_storage.api.inc index f74e8d2..295bc3e 100644 --- a/memcache_storage.api.inc +++ b/memcache_storage.api.inc @@ -542,15 +542,19 @@ class MemcacheStorageAPI { // Get array with debug data. $memcache_storage_debug_output = &drupal_static('memcache_storage_debug_output'); + // Log entries about memcache action. if (is_array($cache_id)) { foreach ($cache_id as $cid) { + + //create an id tag for the ajax return wrapper $memcache_storage_debug_output[] = array( 'action' => count($cache_id) > 1 ? $method . 'Multiple' : $method, 'timer' => timer_read(self::$debug_key), 'memory' => $used_memory, 'bin' => $cache_bin, 'key' => $cid, + 'clear_link' => '', 'mem_key' => array_search($cid, $memcache_id), 'result' => isset($result[$cid]) ? 'HIT' : 'MISS', ); @@ -563,6 +567,7 @@ class MemcacheStorageAPI { 'memory' => $used_memory, 'bin' => $cache_bin, 'key' => $cache_id, + 'clear_link' => '', 'mem_key' => $memcache_id, 'result' => $result ? 'HIT' : 'MISS', ); diff --git a/memcache_storage.module b/memcache_storage.module index 5e09828..9c3b7fe 100644 --- a/memcache_storage.module +++ b/memcache_storage.module @@ -25,6 +25,13 @@ function memcache_storage_menu() { 'file' => 'memcache_storage.admin.inc', ); + $items['memcache_storage/delete_cid/%/%/%/%'] = array( + 'title' => 'memcache storage manual cache clear', + 'page callback' => 'memcache_storage_clear_cid_ajax_callback', + 'page arguments' => array(2,3,4,5), + 'access arguments' => array('administer memcache storage'), + 'type' => MENU_CALLBACK + ); return $items; } @@ -190,6 +197,9 @@ function memcache_storage_debug_shutdown() { // Rebuild detailed debug output. $detailed_debug = array(); foreach ($debug_output as $row) { + $wrapper_class = preg_replace(array('/_/','/:/'),'-','memcache-storage-wrapper-' . implode('-',array($row['bin'],$row['key']))); + $path = 'memcache_storage/delete_cid/nojs/' . $row['action'] . '/' . $row['bin'] . '/' . $row['key']; + $row['clear_link'] = l('Clear',$path,array('attributes' => array('class' => 'use-ajax'))) . "
"; $detailed_debug[] = array( 'data' => $row, 'style' => $row['result'] == 'MISS' ? 'color:red;' : 'color:black;', @@ -207,7 +217,7 @@ function memcache_storage_debug_shutdown() { $debug_table = array( '#theme' => 'table', - '#header' => array(t('Action'), t('Time, ms'), t('Used memory, KB'), t('Cache bin'), t('Cache key'), t('Memcache key'), t('Result')), + '#header' => array(t('Action'), t('Time, ms'), t('Used memory, KB'), t('Cache bin'), t('Cache key'), t('Clear cache'), t('Memcache key'), t('Result')), '#rows' => $detailed_debug, '#attributes' => array( 'class' => array('memcache-storage-detailed-debug') @@ -216,3 +226,38 @@ function memcache_storage_debug_shutdown() { print render($stats_table) . render($debug_table); } + +/** + * Ajax menu callbackfor clearing cache cids + */ +function memcache_storage_clear_cid_ajax_callback($type,$method,$cache_bin,$cache_id) { + $delete_cid = MemcacheStorageAPI::delete($cache_id,$cache_bin); + //ajax + if ($type == 'ajax') { + if ($delete_cid ) { + $output = t('Cache cleared'); + } + else { + $output = t('Unable to clear'); + } + //id tag to replace with the ajax return wrapper + $class = preg_replace(array('/_/','/:/'),'-','.memcache-storage-wrapper-' . implode('-',array($cache_bin,$cache_id))); + $commands[] = ajax_command_replace($class, $output); + $page = array('#type' => 'ajax', '#commands' => $commands); + ajax_deliver($page); + } + //normal page submit + else { + if ($delete_cid ) { + $output = t("Memcache data from was successfully flushed from ") . $cache_bin . ' '. $cache_id; + } + else { + $output = t("Could not flush memcache data from ") . $cache_bin . ' '. $cache_id; + } + return $output; + } +} + + + +