diff --git a/includes/cache.inc b/includes/cache.inc index 44ff3b3..6af0ced 100644 --- a/includes/cache.inc +++ b/includes/cache.inc @@ -8,20 +8,25 @@ /** * Fetch Views' data from the cache * + * @param $key + * The key to retrieve from cache. * @param $move * Under certain circumstances it makes sense to not get the moved table, but the old one. * One example is views_get_handler. + * @param $reset + * Whether to reste from cache or not. */ -function _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) { +function _views_fetch_data($key = 'base_tables', $move = TRUE, $reset = FALSE) { static $cache = NULL; static $recursion_protection = array(); - if (!isset($cache) || $reset) { + if (!isset($cache[$key]) || $reset) { $start = microtime(TRUE); // NOTE: This happens whether we retrieve them from cache or otherwise. - $data = views_cache_get('views_data', TRUE); + $cid = !empty($key) ? 'views_data:' . $key : 'base_tables'; + $data = views_cache_get($cid, TRUE); if (!empty($data->data)) { - $cache = $data->data; + $cache[$key] = $data->data; } if (empty($cache)) { @@ -33,28 +38,34 @@ function _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) { } _views_data_process_entity_types($cache); - views_cache_set('views_data', $cache, TRUE); + // Save all tables. Also save an extra key for the base tables. + $base_tables = array(); + foreach ($cache as $table => $data) { + if (!empty($data['table']['base'])) { + $base_tables[$table]['table'] = $data['table']; + } + $cid = 'views_data:' . $table; + views_cache_set($cid, $data, TRUE); + } + views_cache_set('views_data:base_tables', $base_tables, TRUE); } } - if (!$table) { - return $cache; - } - if (isset($cache[$table])) { + if (isset($cache[$key])) { // Support old views_data entries conversion. - if (isset($cache[$table]['moved to']) && $move) { - $moved_table = $cache[$table]['moved to']; - if (!empty($recursion_protection[$table])) { + if (isset($cache[$key]['moved to']) && $move) { + $moved_table = $cache[$key]['moved to']; + if (!empty($recursion_protection[$key])) { // recursion detected! return NULL; } - $recursion_protection[$table] = TRUE; + $recursion_protection[$key] = TRUE; $data = _views_fetch_data($moved_table); $recursion_protection = array(); return $data; } else { - return $cache[$table]; + return $cache[$key]; } }