diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-02-16 11:22:15 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2009-02-16 11:22:15 +0000 |
commit | 67961769f46444e5462f63212409ae0e69e217f1 (patch) | |
tree | f3e3b9d6521b2155a924be08746401d7eb621339 /engine | |
parent | 0a6d410bb02de58fe7c9d80b0642cdc12d982939 (diff) | |
download | elgg-67961769f46444e5462f63212409ae0e69e217f1.tar.gz elgg-67961769f46444e5462f63212409ae0e69e217f1.tar.bz2 |
Committing the simplecache for views.
git-svn-id: https://code.elgg.org/elgg/trunk@2759 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/elgglib.php | 64 | ||||
-rw-r--r-- | engine/start.php | 3 |
2 files changed, 63 insertions, 4 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index e21e30e25..40a248d8f 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -397,6 +397,59 @@ return false; + }
+
+ /**
+ * Registers a view to be simply cached
+ *
+ * Views cached in this manner must take no parameters and be login agnostic -
+ * that is to say, they look the same no matter who is logged in (or logged out).
+ *
+ * CSS and the basic jS views are automatically cached like this.
+ *
+ * @param string $viewname View name
+ */
+ function elgg_view_register_simplecache($viewname) {
+
+ global $CONFIG;
+
+ if (!isset($CONFIG->views->simplecache))
+ $CONFIG->views->simplecache = array();
+
+ //if (elgg_view_exists($viewname))
+ $CONFIG->views->simplecache[] = $viewname;
+
+ }
+
+ /**
+ * Regenerates the simple cache.
+ *
+ * @see elgg_view_register_simplecache
+ *
+ */
+ function elgg_view_regenerate_simplecache() {
+
+ global $CONFIG;
+
+ if (isset($CONFIG->views->simplecache)) {
+
+ if (!file_exists($CONFIG->dataroot . 'views_simplecache')) {
+ @mkdir($CONFIG->dataroot . 'views_simplecache');
+ }
+
+ if (!empty($CONFIG->views->simplecache) && is_array($CONFIG->views->simplecache)) {
+ foreach($CONFIG->views->simplecache as $view) {
+ $viewcontents = elgg_view($view);
+ $viewname = md5($view);
+ if ($handle = fopen($CONFIG->dataroot . 'views_simplecache/' . $viewname, 'w')) {
+ fwrite($handle, $viewcontents);
+ fclose($handle);
+ }
+ }
+ }
+
+ }
+
} /** @@ -2106,14 +2159,19 @@ register_page_handler('js','js_page_handler'); extend_view('js/initialise_elgg','embed/js'); // Register an event triggered at system shutdown - register_shutdown_function('__elgg_shutdown_hook'); + register_shutdown_function('__elgg_shutdown_hook');
+ } function elgg_boot() { // Actions register_action('comments/add'); - register_action('comments/delete'); + register_action('comments/delete');
+
+ elgg_view_register_simplecache('css');
+ elgg_view_register_simplecache('js/friendsPickerv1');
+ elgg_view_register_simplecache('js/initialise_elgg'); } /** @@ -2124,6 +2182,6 @@ define('ACCESS_PUBLIC',2); register_elgg_event_handler('init','system','elgg_init'); - register_elgg_event_handler('boot','system','elgg_boot'); + register_elgg_event_handler('boot','system','elgg_boot',1000); ?>
\ No newline at end of file diff --git a/engine/start.php b/engine/start.php index 568cea905..d1484cafd 100644 --- a/engine/start.php +++ b/engine/start.php @@ -185,8 +185,9 @@ //forward("setup.php");
//}
}
-
// System booted, return to normal view
set_input('view', $oldview);
+
+ run_function_once('elgg_view_regenerate_simplecache',time() - (86400 * 7));
?>
\ No newline at end of file |