From 47b33b9b54610ddf676201acb408bef691c7eac4 Mon Sep 17 00:00:00 2001 From: marcus Date: Tue, 4 Nov 2008 10:45:40 +0000 Subject: Moved caching to function so it can be easily replaced git-svn-id: https://code.elgg.org/elgg/trunk@2390 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/database.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'engine/lib/database.php') diff --git a/engine/lib/database.php b/engine/lib/database.php index e9f3667f7..0e5b43106 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -23,7 +23,7 @@ function establish_db_link($dblinkname = "readwrite") { // Get configuration, and globalise database link - global $CONFIG, $dblink; + global $CONFIG, $dblink, $DB_QUERY_CACHE; if (!isset($dblink)) { $dblink = array(); @@ -54,7 +54,10 @@ throw new DatabaseException(sprintf(elgg_echo('DatabaseException:WrongCredentials'), $CONFIG->dbuser, $CONFIG->dbhost, $CONFIG->debug ? $CONFIG->dbpass : "****")); if (!mysql_select_db($CONFIG->dbname, $dblink[$dblinkname])) throw new DatabaseException(sprintf(elgg_echo('DatabaseException:NoConnect'), $CONFIG->dbname)); - + + // Set up cache + if (!$DB_QUERY_CACHE) + $DB_QUERY_CACHE = select_default_memcache('db_query_cache'); //array(); } /** @@ -158,7 +161,6 @@ $resultarray = array(); - if (!$DB_QUERY_CACHE) $DB_QUERY_CACHE = new ElggStaticVariableCache('db_query_cache'); //array(); if (isset($DB_QUERY_CACHE[$query])) { if ((isset($CONFIG->debug)) && ($CONFIG->debug==true)) error_log ("$query results returned from cache"); @@ -209,7 +211,6 @@ $dblink = get_db_link('read'); - if (!$DB_QUERY_CACHE) $DB_QUERY_CACHE = new ElggStaticVariableCache('db_query_cache'); //array(); if (isset($DB_QUERY_CACHE[$query])) { if ((isset($CONFIG->debug)) && ($CONFIG->debug==true)) error_log ("$query results returned from cache"); @@ -265,10 +266,7 @@ } // Invalidate query cache - if ($DB_QUERY_CACHE) - $DB_QUERY_CACHE->clear(); - else - $DB_QUERY_CACHE = new ElggStaticVariableCache('db_query_cache'); //array(); + if ($DB_QUERY_CACHE) $DB_QUERY_CACHE->clear(); if ((isset($CONFIG->debug)) && ($CONFIG->debug==true)) error_log("Query cache invalidated"); @@ -304,10 +302,7 @@ } // Invalidate query cache - if ($DB_QUERY_CACHE) - $DB_QUERY_CACHE->clear(); - else - $DB_QUERY_CACHE = new ElggStaticVariableCache('db_query_cache'); //array(); + if ($DB_QUERY_CACHE) $DB_QUERY_CACHE->clear(); if ((isset($CONFIG->debug)) && ($CONFIG->debug==true)) error_log("Query cache invalidated"); @@ -344,10 +339,7 @@ } // Invalidate query cache - if ($DB_QUERY_CACHE) - $DB_QUERY_CACHE->clear(); - else - $DB_QUERY_CACHE = new ElggStaticVariableCache('db_query_cache'); //array(); + if ($DB_QUERY_CACHE) $DB_QUERY_CACHE->clear(); if ((isset($CONFIG->debug)) && ($CONFIG->debug==true)) error_log("Query cache invalidated"); -- cgit v1.2.3