• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

includes/cache.inc

Go to the documentation of this file.
00001 <?php
00016 function _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) {
00017   static $cache = NULL;
00018   static $recursion_protection = array();
00019   if (!isset($cache) || $reset) {
00020     $start = microtime(TRUE);
00021     // NOTE: This happens whether we retrieve them from cache or otherwise.
00022 
00023     $data = views_cache_get('views_data', TRUE);
00024     if (!empty($data->data)) {
00025       $cache = $data->data;
00026     }
00027 
00028     if (empty($cache)) {
00029       views_include_handlers();
00030       $cache = module_invoke_all('views_data');
00031       foreach (module_implements('views_data_alter') as $module) {
00032         $function = $module . '_views_data_alter';
00033         $function($cache);
00034       }
00035       _views_data_process_entity_types($cache);
00036 
00037       views_cache_set('views_data', $cache, TRUE);
00038     }
00039   }
00040 
00041   if (!$table) {
00042     return $cache;
00043   }
00044   if (isset($cache[$table])) {
00045     // Support old views_data entries conversion.
00046     if (isset($cache[$table]['moved to']) && $move) {
00047       $moved_table = $cache[$table]['moved to'];
00048       if (!empty($recursion_protection[$table])) {
00049         // recursion detected!
00050         return NULL;
00051       }
00052       $recursion_protection[$table] = TRUE;
00053       $data = _views_fetch_data($moved_table);
00054       $recursion_protection = array();
00055       return $data;
00056     }
00057     else {
00058       return $cache[$table];
00059     }
00060   }
00061 
00062   // Return an empty array if there is no match.
00063   return array();
00064 }
00065 
00069 function _views_data_process_entity_types(&$data) {
00070   foreach ($data as $table_name => $table_info) {
00071     // Add in a join from the entity-table if an entity-type is given.
00072     if (!empty($table_info['table']['entity type'])) {
00073       $entity_table = 'views_entity_' . $table_info['table']['entity type'];
00074 
00075       $data[$entity_table]['table']['join'][$table_name] = array(
00076         'left_table' => $table_name,
00077       );
00078       $data[$entity_table]['table']['entity type'] = $table_info['table']['entity type'];
00079       // Copy over the default table group if we have none yet.
00080       if (!empty($table_info['table']['group']) && empty($data[$entity_table]['table']['group'])) {
00081         $data[$entity_table]['table']['group'] = $table_info['table']['group'];
00082       }
00083     }
00084   }
00085 }
00086 
00090 function _views_fetch_plugin_data($type = NULL, $plugin = NULL, $reset = FALSE) {
00091   static $cache = NULL;
00092   if (!isset($cache) || $reset) {
00093     $start = microtime(TRUE);
00094     views_include('plugins');
00095     views_include_handlers();
00096 
00097     $cache = views_discover_plugins();
00098 
00099   }
00100 
00101   if (!$type && !$plugin) {
00102     return $cache;
00103   }
00104   elseif (!$plugin) {
00105     // Not in the if above so the else below won't run
00106     if (isset($cache[$type])) {
00107       return $cache[$type];
00108     }
00109   }
00110   elseif (isset($cache[$type][$plugin])) {
00111     return $cache[$type][$plugin];
00112   }
00113 
00114   // Return an empty array if there is no match.
00115   return array();
00116 }
00117 
00131 function views_cache_set($cid, $data, $use_language = FALSE) {
00132   global $language;
00133 
00134   if (variable_get('views_skip_cache', FALSE)) {
00135     return;
00136   }
00137   if ($use_language) {
00138     $cid .= ':' . $language->language;
00139   }
00140 
00141   cache_set($cid, $data, 'cache_views');
00142 }
00143 
00154 function views_cache_get($cid, $use_language = FALSE) {
00155   global $language;
00156 
00157   if (variable_get('views_skip_cache', FALSE)) {
00158     return 0;
00159   }
00160   if ($use_language) {
00161     $cid .= ':' . $language->language;
00162   }
00163 
00164   return cache_get($cid, 'cache_views');
00165 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1