aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2012-01-24 17:59:12 -0800
committerCash Costello <cash.costello@gmail.com>2012-01-24 17:59:12 -0800
commit618263935a0b01bcef7a94153a41be1a6170154a (patch)
tree99c04314de2b669e8aef22c61ffa24f9aa6b14c5 /engine
parent54bef9fc0b85acaf6950e618bd02aa50befd2acc (diff)
parent7c962fa6cbaf687daafb8588ff601fe664e1392c (diff)
downloadelgg-618263935a0b01bcef7a94153a41be1a6170154a.tar.gz
elgg-618263935a0b01bcef7a94153a41be1a6170154a.tar.bz2
Merge pull request #151 from cash/system_cache
Turn viewpath cache into a system cache
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/cache.php157
-rw-r--r--engine/lib/configuration.php8
-rw-r--r--engine/lib/deprecated-1.8.php6
-rw-r--r--engine/lib/elgglib.php2
-rw-r--r--engine/lib/plugins.php17
-rw-r--r--engine/lib/upgrades/2011010101.php2
-rw-r--r--engine/lib/upgrades/2012012100-1.8.3-system_cache-93100e7d55a24a11.php13
7 files changed, 146 insertions, 59 deletions
diff --git a/engine/lib/cache.php b/engine/lib/cache.php
index 47c3af73c..633c470eb 100644
--- a/engine/lib/cache.php
+++ b/engine/lib/cache.php
@@ -10,15 +10,14 @@
/* Filepath Cache */
/**
- * Returns an ElggCache object suitable for caching view
- * file load paths to disk under $CONFIG->dataroot.
+ * Returns an ElggCache object suitable for caching system information
*
* @todo Can this be done in a cleaner way?
* @todo Swap to memcache etc?
*
- * @return ElggFileCache A cache object suitable for caching file load paths.
+ * @return ElggFileCache
*/
-function elgg_get_filepath_cache() {
+function elgg_get_system_cache() {
global $CONFIG;
/**
@@ -27,36 +26,40 @@ function elgg_get_filepath_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;
}
/**
- * Reset the file path cache.
+ * Reset the system cache by deleting the caches
*
* @return bool
*/
-function elgg_filepath_cache_reset() {
- $cache = elgg_get_filepath_cache();
- $view_types_result = $cache->delete('view_types');
- $views_result = $cache->delete('views');
- return $view_types_result && $views_result;
+function elgg_reset_system_cache() {
+ $cache = elgg_get_system_cache();
+
+ $result = true;
+ $cache_types = array('view_paths', 'view_types');
+ foreach ($cache_types as $type) {
+ $result = $result && $cache->delete($type);
+ }
+ return $result;
}
/**
- * Saves a filepath cache.
+ * Saves a system cache.
*
* @param string $type The type or identifier of the cache
* @param string $data The data to be saved
* @return bool
*/
-function elgg_filepath_cache_save($type, $data) {
+function elgg_save_system_cache($type, $data) {
global $CONFIG;
- if ($CONFIG->viewpath_cache_enabled) {
- $cache = elgg_get_filepath_cache();
+ if ($CONFIG->system_cache_enabled) {
+ $cache = elgg_get_system_cache();
return $cache->save($type, $data);
}
@@ -64,16 +67,16 @@ function elgg_filepath_cache_save($type, $data) {
}
/**
- * Retrieve the contents of the filepath cache.
+ * Retrieve the contents of a system cache.
*
* @param string $type The type of cache to load
* @return string
*/
-function elgg_filepath_cache_load($type) {
+function elgg_load_system_cache($type) {
global $CONFIG;
- if ($CONFIG->viewpath_cache_enabled) {
- $cache = elgg_get_filepath_cache();
+ if ($CONFIG->system_cache_enabled) {
+ $cache = elgg_get_system_cache();
$cached_data = $cache->load($type);
if ($cached_data) {
@@ -85,35 +88,74 @@ function elgg_filepath_cache_load($type) {
}
/**
- * Enables the views file paths disk cache.
+ * Enables the system disk cache.
*
- * Uses the 'viewpath_cache_enabled' datalist with a boolean value.
- * Resets the views paths cache.
+ * Uses the 'system_cache_enabled' datalist with a boolean value.
+ * Resets the system cache.
*
* @return void
*/
-function elgg_enable_filepath_cache() {
+function elgg_enable_system_cache() {
global $CONFIG;
- datalist_set('viewpath_cache_enabled', 1);
- $CONFIG->viewpath_cache_enabled = 1;
- elgg_filepath_cache_reset();
+ datalist_set('system_cache_enabled', 1);
+ $CONFIG->system_cache_enabled = 1;
+ elgg_reset_system_cache();
}
/**
- * Disables the views file paths disk cache.
+ * Disables the system disk cache.
*
- * Uses the 'viewpath_cache_enabled' datalist with a boolean value.
- * Resets the views paths cache.
+ * Uses the 'system_cache_enabled' datalist with a boolean value.
+ * Resets the system cache.
*
* @return void
*/
-function elgg_disable_filepath_cache() {
+function elgg_disable_system_cache() {
global $CONFIG;
- datalist_set('viewpath_cache_enabled', 0);
- $CONFIG->viewpath_cache_enabled = 0;
- elgg_filepath_cache_reset();
+ datalist_set('system_cache_enabled', 0);
+ $CONFIG->system_cache_enabled = 0;
+ elgg_reset_system_cache();
+}
+
+/** @todo deprecate in Elgg 1.9 **/
+
+/**
+ * @access private
+ */
+function elgg_get_filepath_cache() {
+ return elgg_get_system_cache();
+}
+/**
+ * @access private
+ */
+function elgg_filepath_cache_reset() {
+ return elgg_reset_system_cache();
+}
+/**
+ * @access private
+ */
+function elgg_filepath_cache_save($type, $data) {
+ return elgg_save_system_cache($type, $data);
+}
+/**
+ * @access private
+ */
+function elgg_filepath_cache_load($type) {
+ return elgg_load_system_cache($type);
+}
+/**
+ * @access private
+ */
+function elgg_enable_filepath_cache() {
+ return elgg_enable_system_cache();
+}
+/**
+ * @access private
+ */
+function elgg_disable_filepath_cache() {
+ return elgg_disable_system_cache();
}
/* Simplecache */
@@ -353,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.
@@ -368,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/configuration.php b/engine/lib/configuration.php
index cccd69105..772c24930 100644
--- a/engine/lib/configuration.php
+++ b/engine/lib/configuration.php
@@ -599,11 +599,11 @@ function _elgg_load_application_config() {
} else {
$CONFIG->simplecache_enabled = 1;
}
- $viewpath_cache_enabled = datalist_get('viewpath_cache_enabled');
- if ($viewpath_cache_enabled !== false) {
- $CONFIG->viewpath_cache_enabled = $viewpath_cache_enabled;
+ $system_cache_enabled = datalist_get('system_cache_enabled');
+ if ($system_cache_enabled !== false) {
+ $CONFIG->system_cache_enabled = $system_cache_enabled;
} else {
- $CONFIG->viewpath_cache_enabled = 1;
+ $CONFIG->system_cache_enabled = 1;
}
// initialize context here so it is set before the get_input call
diff --git a/engine/lib/deprecated-1.8.php b/engine/lib/deprecated-1.8.php
index e1866498b..4b9d41543 100644
--- a/engine/lib/deprecated-1.8.php
+++ b/engine/lib/deprecated-1.8.php
@@ -1674,7 +1674,7 @@ function get_plugin_list() {
* otherwise you may experience view display artifacts. Do this with the following code:
*
* elgg_regenerate_simplecache();
- * elgg_filepath_cache_reset();
+ * elgg_reset_system_cache();
*
* @deprecated 1.8 Use elgg_generate_plugin_entities() and elgg_set_plugin_priorities()
*
@@ -1841,7 +1841,7 @@ function get_installed_plugins($status = 'all') {
* otherwise you may experience view display artifacts. Do this with the following code:
*
* elgg_regenerate_simplecache();
- * elgg_filepath_cache_reset();
+ * elgg_reset_system_cache();
*
* @deprecated 1.8 Use ElggPlugin->activate()
*
@@ -1882,7 +1882,7 @@ function enable_plugin($plugin, $site_guid = null) {
* otherwise you may experience view display artifacts. Do this with the following code:
*
* elgg_regenerate_simplecache();
- * elgg_filepath_cache_reset();
+ * elgg_reset_system_cache();
*
* @deprecated 1.8 Use ElggPlugin->deactivate()
*
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 476408c61..aba84bd48 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 7968f4a6e..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_filepath_cache_load('views');
- $cached_view_types = elgg_filepath_cache_load('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_filepath_cache_save('views', serialize($CONFIG->views));
- elgg_filepath_cache_save('view_types', serialize($CONFIG->view_types));
- }
-
return $return;
}
diff --git a/engine/lib/upgrades/2011010101.php b/engine/lib/upgrades/2011010101.php
index b063c249b..a1ee92622 100644
--- a/engine/lib/upgrades/2011010101.php
+++ b/engine/lib/upgrades/2011010101.php
@@ -66,7 +66,7 @@ if ($old_enabled_plugins) {
// invalidate caches
elgg_invalidate_simplecache();
-elgg_filepath_cache_reset();
+elgg_reset_system_cache();
// clean up.
remove_metadata($site->guid, 'pluginorder');
diff --git a/engine/lib/upgrades/2012012100-1.8.3-system_cache-93100e7d55a24a11.php b/engine/lib/upgrades/2012012100-1.8.3-system_cache-93100e7d55a24a11.php
new file mode 100644
index 000000000..3a9aae2a1
--- /dev/null
+++ b/engine/lib/upgrades/2012012100-1.8.3-system_cache-93100e7d55a24a11.php
@@ -0,0 +1,13 @@
+<?php
+/**
+ * Elgg 1.8.3 upgrade 2012012100
+ * system_cache
+ *
+ * Convert viewpath cache to system cache
+ */
+
+$value = datalist_get('viewpath_cache_enabled');
+datalist_set('system_cache_enabled', $value);
+
+$query = "DELETE FROM {$CONFIG->dbprefix}datalists WHERE name='viewpath_cache_enabled'";
+delete_data($query);