aboutsummaryrefslogtreecommitdiff
path: root/engine
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
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')
-rw-r--r--engine/lib/cache.php24
-rw-r--r--engine/lib/database.php24
-rw-r--r--engine/lib/entities.php14
3 files changed, 40 insertions, 22 deletions
diff --git a/engine/lib/cache.php b/engine/lib/cache.php
index 399552785..7523a0a68 100644
--- a/engine/lib/cache.php
+++ b/engine/lib/cache.php
@@ -167,7 +167,7 @@
*
* @var unknown_type
*/
- private static $__cache;
+ public static $__cache;
/**
* ID of a cache to use.
@@ -385,4 +385,26 @@
}
}
}
+
+
+ /**
+ * A simple function that selects the default caching engine.
+ *
+ * This function provides a central way to get a cache for storing local variables.
+ *
+ * TODO: Do this better & allow plugin overrides.
+ *
+ * @param string $namespace Define which memory space to use.
+ */
+ function select_default_memcache($namespace = "default")
+ {
+ // hook out to the world ? (can't if using as object cache)
+
+ // if nothing then use shared memory cache.
+
+ // TODO: Use memcache if available?
+
+ return new ElggStaticVariableCache($namespace);
+
+ }
?> \ No newline at end of file
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");
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 1daa46a00..d1c4ba3eb 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -921,7 +921,7 @@
global $ENTITY_CACHE;
if (!$ENTITY_CACHE)
- $ENTITY_CACHE = new ElggStaticVariableCache('entity_cache'); // TODO: Replace with memcache?
+ $ENTITY_CACHE = select_default_memcache('entity_cache'); // TODO: Replace with memcache?
}
/**
@@ -1013,7 +1013,8 @@
if ($result) {
- if (!$SUBTYPE_CACHE) $SUBTYPE_CACHE = new ElggStaticVariableCache('subtype_cache');
+ if (!$SUBTYPE_CACHE)
+ $SUBTYPE_CACHE = select_default_memcache('subtype_cache');
$SUBTYPE_CACHE[$result->id] = $result;
return $result->id;
@@ -1043,7 +1044,8 @@
$result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id");
if ($result) {
- if (!$SUBTYPE_CACHE) $SUBTYPE_CACHE = new ElggStaticVariableCache('subtype_cache');
+ if (!$SUBTYPE_CACHE)
+ $SUBTYPE_CACHE = select_default_memcache('subtype_cache');
$SUBTYPE_CACHE[$subtype_id] = $result;
return $result->subtype;
@@ -1071,7 +1073,8 @@
$result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where type='$type' and subtype='$subtype'");
if ($result) {
- if (!$SUBTYPE_CACHE) $SUBTYPE_CACHE = new ElggStaticVariableCache('subtype_cache');
+ if (!$SUBTYPE_CACHE)
+ $SUBTYPE_CACHE = select_default_memcache('subtype_cache');
$SUBTYPE_CACHE[$result->id] = $result;
return $result->class;
@@ -1100,7 +1103,8 @@
$result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id");
if ($result) {
- if (!$SUBTYPE_CACHE) $SUBTYPE_CACHE = new ElggStaticVariableCache('subtype_cache');
+ if (!$SUBTYPE_CACHE)
+ $SUBTYPE_CACHE = select_default_memcache('subtype_cache');
$SUBTYPE_CACHE[$subtype_id] = $result;
return $result->class;