From 3874c13a404dafd526d7e34ca660239dc34dd300 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 21 Jan 2012 12:16:53 -0500 Subject: switched the function names to system cache --- engine/lib/plugins.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engine/lib/plugins.php') diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 7968f4a6e..bbec52c2e 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -302,8 +302,8 @@ function elgg_load_plugins() { } // Load view caches if available - $cached_view_paths = elgg_filepath_cache_load('views'); - $cached_view_types = elgg_filepath_cache_load('view_types'); + $cached_view_paths = elgg_load_system_cache('views'); + $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) { @@ -334,8 +334,8 @@ function elgg_load_plugins() { // Cache results if (!$cached_view_info) { - elgg_filepath_cache_save('views', serialize($CONFIG->views)); - elgg_filepath_cache_save('view_types', serialize($CONFIG->view_types)); + elgg_save_system_cache('views', serialize($CONFIG->views)); + elgg_save_system_cache('view_types', serialize($CONFIG->view_types)); } return $return; -- cgit v1.2.3 From b466d3e188a001f8d7ede1afbf3927c6dbdeae15 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 21 Jan 2012 13:03:47 -0500 Subject: better location for system cache in data directory --- engine/lib/cache.php | 12 ++++++++---- engine/lib/plugins.php | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'engine/lib/plugins.php') diff --git a/engine/lib/cache.php b/engine/lib/cache.php index 75183d23a..cfda26e52 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -26,7 +26,7 @@ function elgg_get_system_cache() { static $FILE_PATH_CACHE; if (!$FILE_PATH_CACHE) { - $FILE_PATH_CACHE = new ElggFileCache($CONFIG->dataroot); + $FILE_PATH_CACHE = new ElggFileCache($CONFIG->dataroot . 'system_cache/'); } return $FILE_PATH_CACHE; @@ -39,9 +39,13 @@ function elgg_get_system_cache() { */ function elgg_reset_system_cache() { $cache = elgg_get_system_cache(); - $view_types_result = $cache->delete('view_types'); - $views_result = $cache->delete('views'); - return $view_types_result && $views_result; + + $result = true; + $cache_types = array('view_paths', 'view_types'); + foreach ($cache_types as $type) { + $result = $result && $cache->delete($type); + } + return $result; } /** diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index bbec52c2e..d9c7b321b 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -302,7 +302,7 @@ function elgg_load_plugins() { } // Load view caches if available - $cached_view_paths = elgg_load_system_cache('views'); + $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); @@ -334,7 +334,7 @@ function elgg_load_plugins() { // Cache results if (!$cached_view_info) { - elgg_save_system_cache('views', serialize($CONFIG->views)); + elgg_save_system_cache('view_paths', serialize($CONFIG->views)); elgg_save_system_cache('view_types', serialize($CONFIG->view_types)); } -- cgit v1.2.3 From 7c962fa6cbaf687daafb8588ff601fe664e1392c Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 21 Jan 2012 13:33:40 -0500 Subject: moved cache loading out of plugin code --- engine/lib/cache.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- engine/lib/elgglib.php | 2 ++ engine/lib/plugins.php | 17 +---------------- 3 files changed, 50 insertions(+), 18 deletions(-) (limited to 'engine/lib/plugins.php') diff --git a/engine/lib/cache.php b/engine/lib/cache.php index cfda26e52..633c470eb 100644 --- a/engine/lib/cache.php +++ b/engine/lib/cache.php @@ -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'); diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 98e7af2a9..3c56567e9 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -2080,6 +2080,8 @@ function _elgg_engine_boot() { _elgg_load_application_config(); _elgg_load_site_config(); + + _elgg_load_cache(); } /** diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index d9c7b321b..07b21d276 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -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; } -- cgit v1.2.3