summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2002-12-11 22:00:04 +0000
committerDries Buytaert <dries@buytaert.net>2002-12-11 22:00:04 +0000
commitb6b24c28e046bbd0bddb9b2b65ca9d4bddff24c8 (patch)
tree8cb31a5aa7568084b9a785f8154f72a2b41fc419 /includes
parent56ac29fad891078c20c06e3d5e1f29a045f65e13 (diff)
downloadbrdo-b6b24c28e046bbd0bddb9b2b65ca9d4bddff24c8.tar.gz
brdo-b6b24c28e046bbd0bddb9b2b65ca9d4bddff24c8.tar.bz2
Applied patch by Natrak:
- page_header() now adds Last-Modified and ETag http headers. - When running PHP as an Apache module page_header() will check the HTTP headers for conditional gets, and will only push the content when it fails. (Works for html and xml pages as they are all cached). Note: this is a PHP limitation, so until PHP makes it work for other web servers this won't work for them. - Added created field to cache database to hold the timestamp when the cache was created. - Changed cache_get() to return an object with ->data and ->created. - Update forum and locale modules.
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc25
1 files changed, 18 insertions, 7 deletions
diff --git a/includes/common.inc b/includes/common.inc
index a7e5164d2..9fd254497 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -462,16 +462,17 @@ function format_size($size) {
}
function cache_get($key) {
- $cache = db_fetch_object(db_query("SELECT data FROM cache WHERE cid = '%s'", $key));
- return $cache->data ? $cache->data : 0;
+ $cache = db_fetch_object(db_query("SELECT data, created FROM cache WHERE cid = '%s'", $key));
+ $created = $cache->created;
+ return $cache->data ? $cache : 0;
}
function cache_set($cid, $data, $expire = 0) {
if (db_fetch_object(db_query("SELECT cid FROM cache WHERE cid = '%s'", $cid))) {
- db_query("UPDATE cache SET data = '%s' WHERE cid = '%s'", $data, $cid);
+ db_query("UPDATE cache SET data = '%s', created = %d, expire = %d WHERE cid = '%s'", $data, time(), $expire, $cid);
}
else {
- db_query("INSERT INTO cache (cid, data, expire) VALUES('%s', '%s', '%s')", $cid, $data, $expire);
+ db_query("INSERT INTO cache (cid, data, created, expire) VALUES('%s', '%s', %d, %d)", $cid, $data, time(), $expire);
}
}
@@ -515,7 +516,7 @@ function page_get_cache() {
}
}
- return $cache ? $cache : 0;
+ return $cache;
}
function format_interval($timestamp) {
@@ -764,8 +765,18 @@ function page_header() {
}
if (variable_get("cache", 0)) {
- if ($data = page_get_cache()) {
- print $data;
+ if ($cache = page_get_cache()) {
+ $date = gmdate("D, d M Y H:i:s", $cache->created) ." GMT";
+ header("Last-Modified: $date");
+ header("ETag: \"$date\"");
+ if ($headers = getallheaders()) {
+ // NOTE: the above is an Apache-ism so for the time being we don't send 304 headers to IIS servers.
+ if ($headers["If-Modified-Since"] == $date && $headers["If-None-Match"] == "\"$date\"") {
+ header("HTTP/1.0 304 Not Modified");
+ exit();
+ }
+ }
+ print $cache->data;
exit();
}
}