function performance_traverse_cache in Performance Logging and Monitoring 6.2
Same name and namespace in other branches
- 7.2 performance.module \performance_traverse_cache()
Helper function to traverse the cache_bin data for retrieving and/or pruning data.
Parameters
$callback string function to execute on the data fetched:
$args optional additional argument(s) to pass to the callback (use an: array or object to pass multiple arguments)
Return value
array of data where the contents depends on the callback
4 calls to performance_traverse_cache()
- drush_performance_summary in ./
performance.drush.inc - Summary page callback. Differs a little from the version in the module because drush_print_table() works differently.
- performance_cron in ./
performance.module - Implementation of hook_cron().
- performance_gather_summary_data in ./
performance.module - Gather performance data for external modules.
- performance_view_summary in ./
performance.module - Summary page callback.
File
- ./
performance.module, line 414 - Logs detailed and/or summary page generation time and memory consumption for page requests. Copyright Khalid Baheyeldin 2008 of http://2bits.com
Code
function performance_traverse_cache($callback, $args = NULL) {
$data_list = array();
$pruned = FALSE;
if ($keys_cache = cache_get(PERFORMANCE_KEY, PERFORMANCE_BIN)) {
// is_array() check to prevent anything from ever going wrong here.
if (is_array($keys_cache->data)) {
foreach ($keys_cache->data as $key => $value) {
$cache = cache_get($key, PERFORMANCE_BIN);
if (!$cache) {
// Cache entry for this key has expired, remove the key.
unset($keys_cache->data[$key]);
// Mark as pruned: we have to rewrite the keys cache!
$pruned = TRUE;
}
else {
// call_user_func() does not support passing by reference. See
// http://php.net/manual/en/function.call-user-func-array.php and the
// note about PHP 5.4 concerning the possibility of passing by
// reference there. Hence this approach to prevent future
// compatibility issues
if ($data = call_user_func($callback, $cache, $args)) {
$data_list[] = $data;
}
}
}
}
}
// Write the pruned key cache if needed.
if ($pruned) {
cache_set(PERFORMANCE_KEY, $keys_cache->data, PERFORMANCE_BIN);
}
return $data_list;
}