aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/lib/views.php23
-rw-r--r--simplecache/view.php20
2 files changed, 34 insertions, 9 deletions
diff --git a/engine/lib/views.php b/engine/lib/views.php
index 6afcc5b76..cceb71c55 100644
--- a/engine/lib/views.php
+++ b/engine/lib/views.php
@@ -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.
diff --git a/simplecache/view.php b/simplecache/view.php
index f04ca0118..67c310d87 100644
--- a/simplecache/view.php
+++ b/simplecache/view.php
@@ -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) {