#10862: Smarter filter cache wiping.

4.5.x
Steven Wittens 2004-09-15 20:34:35 +00:00
parent d00f4a4ebf
commit f8b429e963
8 changed files with 39 additions and 15 deletions

View File

@ -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;
--

View File

@ -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

View File

@ -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);

View File

@ -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());
}
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 {

View File

@ -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 {