]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
moved cache loading out of plugin code
authorCash Costello <cash.costello@gmail.com>
Sat, 21 Jan 2012 18:33:40 +0000 (13:33 -0500)
committerCash Costello <cash.costello@gmail.com>
Sat, 21 Jan 2012 18:33:40 +0000 (13:33 -0500)
engine/lib/cache.php
engine/lib/elgglib.php
engine/lib/plugins.php

index cfda26e52c1cb223fbb9ebef45b1dc185b37c04b..633c470eb066343f4e23c78dcf59842221bb55b4 100644 (file)
@@ -395,7 +395,40 @@ function elgg_invalidate_simplecache() {
        return $return;
 }
 
-function elgg_cache_init() {
+/**
+ * @see elgg_reset_system_cache()
+ * @access private
+ */
+function _elgg_load_cache() {
+       global $CONFIG;
+       
+       $result = true;
+       $cache_types = array(
+               'view_paths' => 'views',
+               'view_types' => 'view_types',
+       );
+       $data = array();
+       foreach ($cache_types as $type => $var_name) {
+               $data[$var_name] = elgg_load_system_cache($type);
+               $result = $result && is_string($data[$var_name]);
+       }
+
+       if ($result) {
+               $CONFIG->system_cache_loaded = true;
+               foreach ($data as $name => $value) {
+                       $CONFIG->$name = unserialize($value);
+               }
+       } else {
+               $CONFIG->system_cache_loaded = false;
+       }
+}
+
+/**
+ * @access private
+ */
+function _elgg_cache_init() {
+       global $CONFIG;
+
        $viewtype = elgg_get_viewtype();
 
        // Regenerate the simple cache if expired.
@@ -410,6 +443,18 @@ function elgg_cache_init() {
                }
                $CONFIG->lastcache = $lastcached;
        }
+
+       // cache system data if enabled and not loaded
+       if ($CONFIG->system_cache_enabled && !$CONFIG->system_cache_loaded) {
+               $cache_types = array(
+                       'view_paths' => 'views',
+                       'view_types' => 'view_types',
+               );
+               $data = array();
+               foreach ($cache_types as $type => $var_name) {
+                       elgg_save_system_cache($type, serialize($CONFIG->$var_name));
+               }
+       }
 }
 
-elgg_register_event_handler('ready', 'system', 'elgg_cache_init');
\ No newline at end of file
+elgg_register_event_handler('ready', 'system', '_elgg_cache_init');
index 98e7af2a97c66458f9041697e64a7f9d34c8646f..3c56567e9cf5a1cf48143fbfb1a1ec8667fba8e4 100644 (file)
@@ -2080,6 +2080,8 @@ function _elgg_engine_boot() {
        _elgg_load_application_config();
 
        _elgg_load_site_config();
+
+       _elgg_load_cache();
 }
 
 /**
index d9c7b321b870da8da06916b5d01dafdb61420585..07b21d276b3727490798b62f2260adf38426f371 100644 (file)
@@ -301,16 +301,7 @@ function elgg_load_plugins() {
                return false;
        }
 
-       // Load view caches if available
-       $cached_view_paths = elgg_load_system_cache('view_paths');
-       $cached_view_types = elgg_load_system_cache('view_types');
-       $cached_view_info = is_string($cached_view_paths) && is_string($cached_view_types);
-
-       if ($cached_view_info) {
-               $CONFIG->views = unserialize($cached_view_paths);
-               $CONFIG->view_types = unserialize($cached_view_types);
-
-               // don't need to register views
+       if (elgg_get_config('system_cache_loaded')) {
                $start_flags = $start_flags & ~ELGG_PLUGIN_REGISTER_VIEWS;
        }
 
@@ -332,12 +323,6 @@ function elgg_load_plugins() {
                }
        }
 
-       // Cache results
-       if (!$cached_view_info) {
-               elgg_save_system_cache('view_paths', serialize($CONFIG->views));
-               elgg_save_system_cache('view_types', serialize($CONFIG->view_types));
-       }
-
        return $return;
 }