From 9e32c2e9606079e72c58075d9167634dcfc65a01 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 17 Nov 2002 06:42:52 +0000 Subject: 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. --- includes/common.inc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'includes') 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(); -- cgit v1.2.3