--- modules/update/update.compare.inc 2008-01-21 13:59:47.000000000 -0500 +++ modules/update/update.compare.new.inc 2008-01-21 14:32:19.000000000 -0500 @@ -21,11 +21,17 @@ * */ function update_get_projects() { - static $projects = array(); - if (empty($projects)) { - _update_process_info_list($projects, module_rebuild_cache(), 'module'); - _update_process_info_list($projects, system_theme_data(), 'theme'); - } + // Retrieve the projects from cache, if present. + $projects = update_project_cache('update_project_projects'); + // If $projects is empty, then the cache must be rebuilt. + // Otherwise, just return the cached data and skip the rest of the function. + if (!empty($projects)) { + return $projects; + } + _update_process_info_list($projects, module_rebuild_cache(), 'module'); + _update_process_info_list($projects, system_theme_data(), 'theme'); + // Set the projects array into the cache table. + cache_set('update_project_projects', $projects, 'cache_update', time() + 3600); return $projects; } @@ -233,6 +239,13 @@ function update_process_project_info(&$p * @see update_process_project_info() */ function update_calculate_project_data($available) { + // Retrieve the projects from cache, if present. + $projects = update_project_cache('update_project_data'); + // If $projects is empty, then the cache must be rebuilt. + // Otherwise, just return the cached data and skip the rest of the function. + if (!empty($projects)) { + return $projects; + } $projects = update_get_projects(); update_process_project_info($projects); foreach ($projects as $project => $project_info) { @@ -543,5 +556,38 @@ function update_calculate_project_data($ // contrib module to provide fine-grained settings to ignore specific // projects or releases). drupal_alter('update_status', $projects); + + // Set the projects array into the cache table. + cache_set('update_project_data', $projects, 'cache_update', time() + 3600); + + return $projects; +} + +/** + * Store the project data in the cache table and empty + * the cache when necessary. + * @param $cid + * The class of data to return from the cache. Valid options are + * 'update_project_data' and 'update_project_projects'. + * @return + * The $projects array generated by update_calculate_project_data() + * and stored in the {cache_update} table. Returns an empty array + * when the cache is cleared. + */ +function update_project_cache($cid) { + $projects = array(); + // In some cases, we must clear the cache. Rather than do so on a time + // basis, we check for specific paths. + $q = $_GET['q']; + $paths = array('admin/build/modules', 'admin/build/themes', 'admin/reports', 'admin/reports/updates', 'admin/reports/status', 'admin/reports/updates/check'); + if (in_array($q, $paths)) { + cache_clear_all($cid, 'cache_update'); + } + else { + $cache = cache_get($cid, 'cache_update'); + if (!empty($cache->data)) { + $projects = $cache->data; + } + } return $projects; }