function _views_fetch_data

Fetch Views' data from the cache.

Parameters

string $table:

bool $move: Under certain circumstances it makes sense to not get the moved table, but the old one. One example is views_get_handler.

bool $reset:

1 call to _views_fetch_data()
views_fetch_data in ./views.module
Fetch Views' data from the cache.

File

includes/cache.inc, line 17

Code

function _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) {
    $cache =& drupal_static(__FUNCTION__ . '_cache');
    $recursion_protection =& drupal_static(__FUNCTION__ . '_recursion_protected');
    $fully_loaded =& drupal_static(__FUNCTION__ . '_fully_loaded');
    if ($reset) {
        $cache = NULL;
        $fully_loaded = FALSE;
    }
    if ($table) {
        if (!isset($cache[$table])) {
            $cid = 'views_data:' . $table;
            if ($data = views_cache_get($cid, TRUE)) {
                $cache[$table] = $data->data;
            }
            else {
                if (!$fully_loaded) {
                    // Try to load the full views cache.
                    if ($data = views_cache_get('views_data', TRUE)) {
                        $cache = $data->data;
                    }
                    else {
                        // No cache entry, rebuild.
                        $cache = _views_fetch_data_build();
                    }
                    $fully_loaded = TRUE;
                }
                // Write back a cache for this table.
                if (isset($cache[$table])) {
                    views_cache_set($cid, $cache[$table], TRUE);
                }
                else {
                    // If there is still no information about that table, it is missing.
                    // Write an empty array to avoid repeated rebuilds.
                    views_cache_set($cid, array(), TRUE);
                }
            }
        }
        if (isset($cache[$table])) {
            if (isset($cache[$table]['moved to']) && $move) {
                $moved_table = $cache[$table]['moved to'];
                if (!empty($recursion_protection[$table])) {
                    // Recursion detected!
                    return NULL;
                }
                $recursion_protection[$table] = TRUE;
                $data = _views_fetch_data($moved_table);
                $recursion_protection = array();
                return $data;
            }
            return $cache[$table];
        }
    }
    else {
        if (!$fully_loaded) {
            if ($data = views_cache_get('views_data', TRUE)) {
                $cache = $data->data;
            }
            else {
                // No cache entry, rebuild.
                $cache = _views_fetch_data_build();
            }
            $fully_loaded = TRUE;
        }
        return $cache;
    }
    // Return an empty array if there is no match.
    return array();
}