summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2001-06-30 20:23:33 +0000
committerDries Buytaert <dries@buytaert.net>2001-06-30 20:23:33 +0000
commit87575929a5a540b7085d3376fb34548cba130bdd (patch)
treefacd2c1d316c0f7d532e8ba983f5782f0befc87a /includes
parenteacfc0425d8e6905e048f3ab934e4baa00b0abb3 (diff)
downloadbrdo-87575929a5a540b7085d3376fb34548cba130bdd.tar.gz
brdo-87575929a5a540b7085d3376fb34548cba130bdd.tar.bz2
- Introduced caching support.
Diffstat (limited to 'includes')
-rw-r--r--includes/comment.inc3
-rw-r--r--includes/common.inc39
2 files changed, 42 insertions, 0 deletions
diff --git a/includes/comment.inc b/includes/comment.inc
index d5ccda112..428245a02 100644
--- a/includes/comment.inc
+++ b/includes/comment.inc
@@ -126,6 +126,9 @@ function comment_post($edit) {
// add comment to database:
db_query("INSERT INTO comments (lid, pid, author, subject, comment, hostname, timestamp, score) VALUES ('". check_input($edit[id]) ."', '". check_input($edit[pid]) ."', '$user->id', '". check_input($edit[subject]) ."', '". check_input($edit[comment]) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."', '". ($user->userid ? 1 : 0) ."')");
+
+ // clear cache:
+ cache_clear();
}
}
}
diff --git a/includes/common.inc b/includes/common.inc
index a5cbba931..c21036961 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -87,6 +87,34 @@ function format_plural($count, $singular, $plural) {
return ($count == 1) ? "$count ". t($singular) : "$count ". t($plural);
}
+function cache_clear($interval = 0) {
+ db_query("DELETE FROM cache WHERE ". time() ." - timestamp > $interval");
+}
+
+function cache_get() {
+ global $user, $REQUEST_URI, $REQUEST_METHOD;
+
+ if ($user->id || $REQUEST_METHOD != "GET") {
+ return 0;
+ }
+
+ if ($cache = db_fetch_object(db_query("SELECT * FROM cache WHERE url = '". check_input($REQUEST_URI) ."'"))) {
+ cache_clear(variable_get("cache_clear", 30));
+
+ return $cache->data;
+ }
+
+ ob_start();
+
+ return 0;
+}
+
+function cache_set() {
+ global $REQUEST_URI;
+
+ db_query("INSERT INTO cache (url, data, timestamp) VALUES('". check_input($REQUEST_URI) ."', '". check_code(ob_get_contents()) ."', '". time() ."')");
+}
+
function format_interval($timestamp) {
$units = array("year|years" => 31536000, "week|weeks" => 604800, "day|days" => 86400, "hour|hours" => 3600, "min|min" => 60, "sec|sec" => 1);
foreach ($units as $key=>$value) {
@@ -245,12 +273,23 @@ function page_header() {
if (variable_get("dev_timer", 0)) {
timer_start();
}
+
+ if (variable_get("cache", 0)) {
+ if ($data = cache_get()) {
+ print $data;
+ exit();
+ }
+ }
}
function page_footer() {
if (variable_get("dev_timer", 0)) {
timer_print();
}
+
+ if (variable_get("cache", 0)) {
+ cache_set();
+ }
}
$conf = conf_init();