]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2410 - merged [7024] into trunk from 1.7 branch
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 20 Oct 2010 23:16:46 +0000 (23:16 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 20 Oct 2010 23:16:46 +0000 (23:16 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7109 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/views.php
simplecache/view.php

index 6afcc5b7681d773ad42ded52d829b4d85ee3e2e3..cceb71c559a74cee65b09f2cb643f3b193078904 100644 (file)
@@ -545,6 +545,29 @@ function elgg_view_disable_simplecache() {
        }
 }
 
+/**
+ * Invalidates all cached views in the simplecache
+ *
+ * @since 1.7.4
+ */
+function elgg_invalidate_simplecache() {
+       global $CONFIG;
+
+       $return = TRUE;
+
+       if ($handle = opendir($CONFIG->dataroot . 'views_simplecache')) {
+               while (false !== ($file = readdir($handle))) {
+                       if ($file != "." && $file != "..") {
+                               $return = $return && unlink($CONFIG->dataroot.'views_simplecache/'.$file);
+                       }
+               }
+               closedir($handle);
+       } else {
+               $return = FALSE;
+       }
+
+       return $return;
+}
 
 /**
  * Returns the name of views for in a directory.
index f04ca01181d03335cead4ef0d76d58eb146efcea..67c310d8722a90b6dfb557f12cd2c1825c2a5f13 100644 (file)
@@ -14,10 +14,11 @@ require_once(dirname(dirname(__FILE__)). '/engine/settings.php');
 
 global $CONFIG, $viewinput, $override;
 if (!isset($override)) {
-       $override = false;
+       $override = FALSE;
 }
 
 $contents = '';
+
 if (!isset($viewinput)) {
        $viewinput = $_GET;
 }
@@ -51,21 +52,22 @@ if ($mysql_dblink = @mysql_connect($CONFIG->dbhost,$CONFIG->dbuser,$CONFIG->dbpa
                        $filename = $dataroot . 'views_simplecache/' . md5($viewtype . $view_name);
                        if (file_exists($filename)) {
                                $contents = file_get_contents($filename);
-                               header("Content-Length: " . strlen($contents));
                        } else {
                                mysql_query("INSERT into {$CONFIG->dbprefix}datalists set name = 'simplecache_lastupdate_$viewtype', value = '0' ON DUPLICATE KEY UPDATE value='0'");
-
-                               echo ''; exit;
                        }
-               } else {
-                       mysql_close($mysql_dblink);
-                       require_once(dirname(dirname(__FILE__)) . "/engine/start.php");
-                       $contents = elgg_view($view_name);
-                       header("Content-Length: " . strlen($contents));
                }
        }
 }
 
+// load full engine if simplecache is disabled, overriden, or invalid
+if (!$contents) {
+       mysql_close($mysql_dblink);
+       require_once(dirname(dirname(__FILE__)) . "/engine/start.php");
+       $contents = elgg_view($view);
+}
+
+header("Content-Length: " . strlen($contents));
+
 $split_output = str_split($contents, 1024);
 
 foreach($split_output as $chunk) {