summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2002-11-17 06:42:52 +0000
committerDries Buytaert <dries@buytaert.net>2002-11-17 06:42:52 +0000
commit9e32c2e9606079e72c58075d9167634dcfc65a01 (patch)
treeba24bf55130fcc3ec59562b35b764bc9e73d4e8e
parent64f8781f789912751849c506a9a412ed27ddd0db (diff)
downloadbrdo-9e32c2e9606079e72c58075d9167634dcfc65a01.tar.gz
brdo-9e32c2e9606079e72c58075d9167634dcfc65a01.tar.bz2
Patch based on work of Kjartan:
- Changed cache API. - Fixed caching bug in comment.module. Odd this hasn't been reported yet. - Fixed caching bug in forum.module. - Fixed caching bug in system.module. - Fixed caching bug in block.module. - Simplified caching support in forum.module thanks to improved cache API.
-rw-r--r--includes/common.inc22
-rw-r--r--modules/block.module6
-rw-r--r--modules/block/block.module6
-rw-r--r--modules/comment.module12
-rw-r--r--modules/comment/comment.module12
-rw-r--r--modules/forum.module19
-rw-r--r--modules/forum/forum.module19
-rw-r--r--modules/node.module7
-rw-r--r--modules/node/node.module7
-rw-r--r--modules/system.module22
-rw-r--r--modules/system/system.module22
11 files changed, 90 insertions, 64 deletions
diff --git a/includes/common.inc b/includes/common.inc
index b85c0530e..28086de9b 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -473,12 +473,22 @@ function cache_set($cid, $data, $expire = 0) {
}
}
-function cache_del($cid) {
- db_query("DELETE FROM cache WHERE cid = '%s'", $cid);
+function cache_clear_all($cid = NULL) {
+ if (empty($cid)) {
+ db_query("DELETE FROM cache");
+ }
+ else {
+ db_query("DELETE FROM cache WHERE cid = '%s'", $cid);
+ }
}
-function cache_clear() {
- db_query("DELETE FROM cache WHERE expire < ". time() ." AND expire > 0");
+function cache_clear_old($cid = NULL) {
+ if (empty($cid)) {
+ db_query("DELETE FROM cache WHERE expire < ". time() ." AND expire > 0");
+ }
+ else {
+ db_query("DELETE FROM cache WHERE cid = '%s' AND expire < %s AND expire > 0", $cid, time());
+ }
}
function page_set_cache() {
@@ -486,7 +496,7 @@ function page_set_cache() {
if (!$user->uid && $REQUEST_METHOD == "GET") {
if ($data = ob_get_contents()) {
- cache_set(request_uri(), $data, (time() + variable_get("cache_clear", 30)));
+ cache_set(request_uri(), $data, (time() + variable_get("cache_clear", 120)));
}
}
}
@@ -496,7 +506,7 @@ function page_get_cache() {
if (!$user->uid && $REQUEST_METHOD == "GET") {
if ($cache = cache_get(request_uri())) {
- cache_clear();
+ cache_clear_old();
}
else {
ob_start();
diff --git a/modules/block.module b/modules/block.module
index f7ec7c24b..847b55aa8 100644
--- a/modules/block.module
+++ b/modules/block.module
@@ -77,6 +77,12 @@ function block_admin_save($edit) {
db_query("UPDATE blocks SET region = '%s', status = '%d', custom = '%d', path = '%s', weight = '%d' WHERE module = '%s' AND delta = '%d'", $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $module, $delta);
}
}
+
+ /*
+ ** Clear the cache so the changes take effect for anonymous users.
+ */
+
+ cache_clear_all();
}
/**
diff --git a/modules/block/block.module b/modules/block/block.module
index f7ec7c24b..847b55aa8 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -77,6 +77,12 @@ function block_admin_save($edit) {
db_query("UPDATE blocks SET region = '%s', status = '%d', custom = '%d', path = '%s', weight = '%d' WHERE module = '%s' AND delta = '%d'", $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $module, $delta);
}
}
+
+ /*
+ ** Clear the cache so the changes take effect for anonymous users.
+ */
+
+ cache_clear_all();
}
/**
diff --git a/modules/comment.module b/modules/comment.module
index 4c0dd1b64..8c1c7b57f 100644
--- a/modules/comment.module
+++ b/modules/comment.module
@@ -276,17 +276,11 @@ function comment_post($edit) {
}
/*
- ** Clear the cache:
+ ** Clear the cache so an anonymous user can see his comment being
+ ** added.
*/
- cache_clear();
-
- /*
- ** TODO: we'd prefer to invalidate the page or pages with the newly
- ** inserted comment.
- **
- ** db_query("DELETE FROM cache WHERE cid LIKE '%s'", "%id=".$edit["nid"]."%");
- */
+ cache_clear_all();
}
}
else {
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 4c0dd1b64..8c1c7b57f 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -276,17 +276,11 @@ function comment_post($edit) {
}
/*
- ** Clear the cache:
+ ** Clear the cache so an anonymous user can see his comment being
+ ** added.
*/
- cache_clear();
-
- /*
- ** TODO: we'd prefer to invalidate the page or pages with the newly
- ** inserted comment.
- **
- ** db_query("DELETE FROM cache WHERE cid LIKE '%s'", "%id=".$edit["nid"]."%");
- */
+ cache_clear_all();
}
}
else {
diff --git a/modules/forum.module b/modules/forum.module
index 46dacdded..d5c1cea80 100644
--- a/modules/forum.module
+++ b/modules/forum.module
@@ -43,7 +43,6 @@ function forum_conf_options() {
$forder = array(1 => "Date - newest first", 2 => "Date - oldest first", 3 => "Posts - most active first", 4=> "Posts - least active first");
$output .= form_select("Default order", "forum_order", variable_get("forum_order", 1), $forder, "The default display order for topics.");
$output .= form_textfield("Number of topics in block", "forum_block_num", variable_get("forum_block_num", "5"), 5, 5, "The number of topics in the <b>Forum topics</b>-block. To enable the block, click ". la("here", array("mod" => "block")) .".");
- $output .= form_select("Internal caching", "forum_cache", variable_get("forum_cache", 0), array("disabled", "enabled"), "Cache internal datastructures for both anonymous and autheticated users. When enabled, the forum data won't be 100% up to date with regards regard to the number of posts, the number of replies and the last topic being posted. Enable when you have busy forum.");
return $output;
}
@@ -91,9 +90,7 @@ function forum_block($op = "list", $delta = 0) {
}
else {
if (user_access("access content")) {
- if (variable_get("forum_cache", 0)) {
- $content = cache_get("forum:block");
- }
+ $content = cache_get("forum:block");
if (!$content) {
unset($items);
@@ -107,7 +104,7 @@ function forum_block($op = "list", $delta = 0) {
$content .= "<div id=\"forum_more\" align=\"right\">". lm(t("more"), array("mod" => "forum")) ."</div>";
}
- cache_set("forum:block", $content, time() + 60 * 3);
+ cache_set("forum:block", $content, time() + variable_get("cache_clear", 120));
}
$blocks["subject"] = t("Forum topics");
@@ -256,10 +253,6 @@ function forum_insert($node) {
// we created a shadow, a link to a moved topic in a new forum
db_query("INSERT INTO forum (nid, icon, shadow) VALUES ('%d', '%s', '%d')", $node->nid, $node->icon, $node->shadow);
}
-
- if (variable_get("forum_cache", 0)) {
- cache_clear();
- }
}
function forum_update($node) {
@@ -326,9 +319,7 @@ function forum_get_forums($tid = 0) {
$tid = 0;
}
- if (variable_get("forum_cache", 0)) {
- $forums = unserialize(cache_get("forum:$tid"));
- }
+ $forums = unserialize(cache_get("forum:$tid"));
if (!$forums) {
$forums = array();
@@ -347,9 +338,7 @@ function forum_get_forums($tid = 0) {
$n++;
}
- if (variable_get("forum_cache", 0)) {
- cache_set("forum:$tid", serialize($forums), time()+60*10);
- }
+ cache_set("forum:$tid", serialize($forums), time() + variable_get("cache_clear", 120));
}
if ($user->uid && $forums) {
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 46dacdded..d5c1cea80 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -43,7 +43,6 @@ function forum_conf_options() {
$forder = array(1 => "Date - newest first", 2 => "Date - oldest first", 3 => "Posts - most active first", 4=> "Posts - least active first");
$output .= form_select("Default order", "forum_order", variable_get("forum_order", 1), $forder, "The default display order for topics.");
$output .= form_textfield("Number of topics in block", "forum_block_num", variable_get("forum_block_num", "5"), 5, 5, "The number of topics in the <b>Forum topics</b>-block. To enable the block, click ". la("here", array("mod" => "block")) .".");
- $output .= form_select("Internal caching", "forum_cache", variable_get("forum_cache", 0), array("disabled", "enabled"), "Cache internal datastructures for both anonymous and autheticated users. When enabled, the forum data won't be 100% up to date with regards regard to the number of posts, the number of replies and the last topic being posted. Enable when you have busy forum.");
return $output;
}
@@ -91,9 +90,7 @@ function forum_block($op = "list", $delta = 0) {
}
else {
if (user_access("access content")) {
- if (variable_get("forum_cache", 0)) {
- $content = cache_get("forum:block");
- }
+ $content = cache_get("forum:block");
if (!$content) {
unset($items);
@@ -107,7 +104,7 @@ function forum_block($op = "list", $delta = 0) {
$content .= "<div id=\"forum_more\" align=\"right\">". lm(t("more"), array("mod" => "forum")) ."</div>";
}
- cache_set("forum:block", $content, time() + 60 * 3);
+ cache_set("forum:block", $content, time() + variable_get("cache_clear", 120));
}
$blocks["subject"] = t("Forum topics");
@@ -256,10 +253,6 @@ function forum_insert($node) {
// we created a shadow, a link to a moved topic in a new forum
db_query("INSERT INTO forum (nid, icon, shadow) VALUES ('%d', '%s', '%d')", $node->nid, $node->icon, $node->shadow);
}
-
- if (variable_get("forum_cache", 0)) {
- cache_clear();
- }
}
function forum_update($node) {
@@ -326,9 +319,7 @@ function forum_get_forums($tid = 0) {
$tid = 0;
}
- if (variable_get("forum_cache", 0)) {
- $forums = unserialize(cache_get("forum:$tid"));
- }
+ $forums = unserialize(cache_get("forum:$tid"));
if (!$forums) {
$forums = array();
@@ -347,9 +338,7 @@ function forum_get_forums($tid = 0) {
$n++;
}
- if (variable_get("forum_cache", 0)) {
- cache_set("forum:$tid", serialize($forums), time()+60*10);
- }
+ cache_set("forum:$tid", serialize($forums), time() + variable_get("cache_clear", 120));
}
if ($user->uid && $forums) {
diff --git a/modules/node.module b/modules/node.module
index 9424b3ac0..f086eaa0e 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -209,6 +209,13 @@ function node_save($node, $filter) {
}
/*
+ ** Clear the cache so an anonymous poster can see the node being added
+ ** or updated.
+ */
+
+ cache_clear_all();
+
+ /*
** Return the node ID:
*/
diff --git a/modules/node/node.module b/modules/node/node.module
index 9424b3ac0..f086eaa0e 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -209,6 +209,13 @@ function node_save($node, $filter) {
}
/*
+ ** Clear the cache so an anonymous poster can see the node being added
+ ** or updated.
+ */
+
+ cache_clear_all();
+
+ /*
** Return the node ID:
*/
diff --git a/modules/system.module b/modules/system.module
index 91d2524b6..4ca23b860 100644
--- a/modules/system.module
+++ b/modules/system.module
@@ -15,7 +15,7 @@ function system_system($field){
function system_help_cache() {
$output .= "<p>Drupal has a caching mechanism that stores dynamically generated pages in a database. By caching a page, Drupal does not have to generate the page each time it is requested. Only pages requested by anonymous users are being cached. When a cached page is accessed, Drupal will retrieve that page with minimal overhead using one SQL query only, thus reducing both the server load and the response time.</p>";
- $output .= "<p>Drupal's caching mechanism can be enabled and disabled by the site administrators from the 'settings' page. He can also define how long cached pages should be kept.</p>";
+ $output .= "<p>Drupal's caching mechanism can be enabled and disabled by the site administrators from the 'settings' page. Site administrators can also define how long cached pages should be kept.</p>";
return $output;
}
@@ -59,7 +59,7 @@ function system_view_options() {
$output .= "<h3>" . t("Cache settings") . "</h3>\n";
$period = array(10 => format_interval(10), 20 => format_interval(20), 30 => format_interval(30), 40 => format_interval(40), 50 => format_interval(50), 50 => format_interval(50), 60 => format_interval(60), 90 => format_interval(90), 120 => format_interval(120), 150 => format_interval(150), 180 => format_interval(180), 210 => format_interval(210), 240 => format_interval(240), 270 => format_interval(270), 300 => format_interval(300), 360 => format_interval(360), 420 => format_interval(420), 480 => format_interval(480), 540 => format_interval(540), 600 => format_interval(600), 1800 => format_interval(1800), 3600 => format_interval(3600), 7200 => format_interval(7200));
$output .= form_select(t("Cache support"), "cache", variable_get("cache", 0), array(t("Disabled"), t("Enabled")), t("Enable or disable the caching of pages."));
- $output .= form_select(t("Discard cached pages older than"), "cache_clear", variable_get("cache_clear", 30), $period, t("The time cached pages should be kept. Older pages are automatically refreshed."));
+ $output .= form_select(t("Discard cached pages older than"), "cache_clear", variable_get("cache_clear", 120), $period, t("The time cached pages should be kept. Older pages are automatically refreshed."));
$output .= "<hr />\n";
// submission settings:
@@ -105,12 +105,24 @@ function system_view_filters() {
}
function system_save($edit = array()) {
- foreach ($edit as $name => $value) variable_set($name, $value);
+ foreach ($edit as $name => $value) {
+ variable_set($name, $value);
+ }
+
+ /*
+ ** Clear the cache so the changes take effect for anonymous users.
+ */
+
+ cache_clear_all();
+
return t("The configuration options have been saved.");
}
function system_default($edit = array()) {
- foreach ($edit as $name => $value) variable_del($name);
+ foreach ($edit as $name => $value) {
+ variable_del($name);
+ }
+
return t("The configuration options have been reset to their default values.");
}
@@ -197,7 +209,7 @@ function system_listing($type, $directory, $required = array()) {
}
}
- // Clean up database.
+ // Update the contents of the system table:
db_query("DELETE FROM system WHERE filename = '%s' AND type = '%s'", $filename, $type);
db_query("INSERT INTO system (name, description, type, filename, status) VALUES ('%s', '%s', '%s', '%s', %d)", $info->name, $info->description, $type, $filename, $file->status);
diff --git a/modules/system/system.module b/modules/system/system.module
index 91d2524b6..4ca23b860 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -15,7 +15,7 @@ function system_system($field){
function system_help_cache() {
$output .= "<p>Drupal has a caching mechanism that stores dynamically generated pages in a database. By caching a page, Drupal does not have to generate the page each time it is requested. Only pages requested by anonymous users are being cached. When a cached page is accessed, Drupal will retrieve that page with minimal overhead using one SQL query only, thus reducing both the server load and the response time.</p>";
- $output .= "<p>Drupal's caching mechanism can be enabled and disabled by the site administrators from the 'settings' page. He can also define how long cached pages should be kept.</p>";
+ $output .= "<p>Drupal's caching mechanism can be enabled and disabled by the site administrators from the 'settings' page. Site administrators can also define how long cached pages should be kept.</p>";
return $output;
}
@@ -59,7 +59,7 @@ function system_view_options() {
$output .= "<h3>" . t("Cache settings") . "</h3>\n";
$period = array(10 => format_interval(10), 20 => format_interval(20), 30 => format_interval(30), 40 => format_interval(40), 50 => format_interval(50), 50 => format_interval(50), 60 => format_interval(60), 90 => format_interval(90), 120 => format_interval(120), 150 => format_interval(150), 180 => format_interval(180), 210 => format_interval(210), 240 => format_interval(240), 270 => format_interval(270), 300 => format_interval(300), 360 => format_interval(360), 420 => format_interval(420), 480 => format_interval(480), 540 => format_interval(540), 600 => format_interval(600), 1800 => format_interval(1800), 3600 => format_interval(3600), 7200 => format_interval(7200));
$output .= form_select(t("Cache support"), "cache", variable_get("cache", 0), array(t("Disabled"), t("Enabled")), t("Enable or disable the caching of pages."));
- $output .= form_select(t("Discard cached pages older than"), "cache_clear", variable_get("cache_clear", 30), $period, t("The time cached pages should be kept. Older pages are automatically refreshed."));
+ $output .= form_select(t("Discard cached pages older than"), "cache_clear", variable_get("cache_clear", 120), $period, t("The time cached pages should be kept. Older pages are automatically refreshed."));
$output .= "<hr />\n";
// submission settings:
@@ -105,12 +105,24 @@ function system_view_filters() {
}
function system_save($edit = array()) {
- foreach ($edit as $name => $value) variable_set($name, $value);
+ foreach ($edit as $name => $value) {
+ variable_set($name, $value);
+ }
+
+ /*
+ ** Clear the cache so the changes take effect for anonymous users.
+ */
+
+ cache_clear_all();
+
return t("The configuration options have been saved.");
}
function system_default($edit = array()) {
- foreach ($edit as $name => $value) variable_del($name);
+ foreach ($edit as $name => $value) {
+ variable_del($name);
+ }
+
return t("The configuration options have been reset to their default values.");
}
@@ -197,7 +209,7 @@ function system_listing($type, $directory, $required = array()) {
}
}
- // Clean up database.
+ // Update the contents of the system table:
db_query("DELETE FROM system WHERE filename = '%s' AND type = '%s'", $filename, $type);
db_query("INSERT INTO system (name, description, type, filename, status) VALUES ('%s', '%s', '%s', '%s', %d)", $info->name, $info->description, $type, $filename, $file->status);