aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/database.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-04 10:45:40 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-04 10:45:40 +0000
commit47b33b9b54610ddf676201acb408bef691c7eac4 (patch)
treeb00c8d264fa0b9cfec9b802ade97a87dfa759baf /engine/lib/database.php
parente9a37af94c1cb294f561305c94d4e00e0bc49990 (diff)
downloadelgg-47b33b9b54610ddf676201acb408bef691c7eac4.tar.gz
elgg-47b33b9b54610ddf676201acb408bef691c7eac4.tar.bz2
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
Diffstat (limited to 'engine/lib/database.php')
-rw-r--r--engine/lib/database.php24
1 files changed, 8 insertions, 16 deletions
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");