1 cache.inc | _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) |
Fetch Views' data from the cache.
Parameters
$move: Under certain circumstances it makes sense to not get the moved table, but the old one. One example is views_get_handler.
File
- core/
modules/ views/ includes/ cache.inc, line 14 - Load Views' data so that it knows what is available to build queries from.
Code
function _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) {
$cache = &backdrop_static(__FUNCTION__ . '_cache');
$recursion_protection = &backdrop_static(__FUNCTION__ . '_recursion_protected');
$fully_loaded = &backdrop_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();
}