summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--database/database.mysql3
-rw-r--r--database/database.pgsql1
-rw-r--r--database/updates.inc16
-rw-r--r--includes/bootstrap.inc22
-rw-r--r--modules/archive.module2
-rw-r--r--modules/archive/archive.module2
-rw-r--r--modules/filter.module4
-rw-r--r--modules/filter/filter.module4
8 files changed, 39 insertions, 15 deletions
diff --git a/database/database.mysql b/database/database.mysql
index 45d864e7e..014b63c99 100644
--- a/database/database.mysql
+++ b/database/database.mysql
@@ -165,7 +165,8 @@ CREATE TABLE cache (
expire int(11) NOT NULL default '0',
created int(11) NOT NULL default '0',
headers text,
- PRIMARY KEY (cid)
+ PRIMARY KEY (cid),
+ INDEX expire (expire)
) TYPE=MyISAM;
--
diff --git a/database/database.pgsql b/database/database.pgsql
index 339549516..375281dfa 100644
--- a/database/database.pgsql
+++ b/database/database.pgsql
@@ -168,6 +168,7 @@ CREATE TABLE cache (
headers text default '',
PRIMARY KEY (cid)
);
+CREATE INDEX cache_expire_idx ON cache(expire);
--
-- Table structure for comments
diff --git a/database/updates.inc b/database/updates.inc
index 9489780dc..2435492c9 100644
--- a/database/updates.inc
+++ b/database/updates.inc
@@ -81,7 +81,8 @@ $sql_updates = array(
"2004-08-12" => "update_102",
"2004-08-17" => "update_103",
"2004-08-19" => "update_104",
- "2004-09-14" => "update_105"
+ "2004-09-14" => "update_105",
+ "2004-09-15" => "update_106"
);
function update_32() {
@@ -1798,6 +1799,19 @@ function update_105() {
return $ret;
}
+function update_106() {
+ $ret = array();
+ if ($GLOBALS['db_type'] == 'mysql') {
+ $ret[] = update_sql('ALTER TABLE {cache} ADD INDEX expire (expire)');
+ }
+ else if ($GLOBALS['db_type'] == 'pgsql') {
+ // TODO: needs PGSQL equivalent.
+ }
+
+ $ret[] = update_sql('DELETE FROM {cache}');
+ return $ret;
+}
+
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 291eb5bbd..cf55dc173 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -5,6 +5,9 @@
* @file
* Functions that need to be loaded on every Drupal request.
*/
+
+define('CACHE_PERMANENT', 0);
+define('CACHE_TEMPORARY', -1);
/**
* Locate the appropriate configuration file.
@@ -126,18 +129,23 @@ function cache_get($key) {
* @param $data
* The data to store in the cache. Complex data types must be serialized first.
* @param $expire
- * Whether the data should be removed from the cache when a cache expiration
- * is triggered.
+ * One of the following values:
+ * - CACHE_PERMANENT: Indicates that the item should never be removed unless
+ * explicitly told to using cache_clear_all() with a cache ID.
+ * - CACHE_TEMPORARY: Indicates that the item should be removed at the next
+ * general cache wipe.
+ * - A Unix timestamp: Indicates that the item should be kept at least until
+ * the given time, after which it behaves like CACHE_TEMPORARY.
* @param $headers
* A string containing HTTP header information for cached pages.
*/
-function cache_set($cid, $data, $expire = 0, $headers = NULL) {
+function cache_set($cid, $data, $expire = CACHE_PERMANENT, $headers = NULL) {
$data = db_encode_blob($data);
db_query("UPDATE {cache} SET data = '%s', created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid);
if (!db_affected_rows()) {
- db_query("INSERT INTO {cache} (cid, data, created, expire, headers) VALUES('%s', '%s', %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
- }
+ db_query("INSERT INTO {cache} (cid, data, created, expire, headers) VALUES ('%s', '%s', %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
+ }
}
/**
@@ -153,7 +161,7 @@ function cache_set($cid, $data, $expire = 0, $headers = NULL) {
*/
function cache_clear_all($cid = NULL, $wildcard = false) {
if (empty($cid)) {
- db_query("DELETE FROM {cache} WHERE expire <> 0");
+ db_query("DELETE FROM {cache} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
}
else {
if ($wildcard) {
@@ -182,7 +190,7 @@ function page_set_cache() {
$data = gzencode($data, FORCE_GZIP);
}
}
- cache_set($base_url . request_uri(), $data, 1, drupal_get_headers());
+ cache_set($base_url . request_uri(), $data, CACHE_TEMPORARY, drupal_get_headers());
}
}
}
diff --git a/modules/archive.module b/modules/archive.module
index 2e6a78654..21047dae7 100644
--- a/modules/archive.module
+++ b/modules/archive.module
@@ -169,7 +169,7 @@ function archive_calendar($original = 0) {
$output .= "</table></div>\n\n";
- cache_set("archive:calendar:$day-$month-$year", $output, 1);
+ cache_set("archive:calendar:$day-$month-$year", $output, CACHE_TEMPORARY);
return $output;
}
diff --git a/modules/archive/archive.module b/modules/archive/archive.module
index 2e6a78654..21047dae7 100644
--- a/modules/archive/archive.module
+++ b/modules/archive/archive.module
@@ -169,7 +169,7 @@ function archive_calendar($original = 0) {
$output .= "</table></div>\n\n";
- cache_set("archive:calendar:$day-$month-$year", $output, 1);
+ cache_set("archive:calendar:$day-$month-$year", $output, CACHE_TEMPORARY);
return $output;
}
diff --git a/modules/filter.module b/modules/filter.module
index 1cf09d48c..dece83b8e 100644
--- a/modules/filter.module
+++ b/modules/filter.module
@@ -593,9 +593,9 @@ function check_output($text, $format = FILTER_FORMAT_DEFAULT) {
$text = module_invoke($filter->module, 'filter', 'process', $filter->delta, $format, $text);
}
- // Store in cache.
+ // Store in cache with a minimum expiration time of 1 day.
if ($cache) {
- cache_set($id, $text, 1);
+ cache_set($id, $text, time() + (60 * 60 * 24));
}
}
else {
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index 1cf09d48c..dece83b8e 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -593,9 +593,9 @@ function check_output($text, $format = FILTER_FORMAT_DEFAULT) {
$text = module_invoke($filter->module, 'filter', 'process', $filter->delta, $format, $text);
}
- // Store in cache.
+ // Store in cache with a minimum expiration time of 1 day.
if ($cache) {
- cache_set($id, $text, 1);
+ cache_set($id, $text, time() + (60 * 60 * 24));
}
}
else {