From e9a37af94c1cb294f561305c94d4e00e0bc49990 Mon Sep 17 00:00:00 2001 From: marcus Date: Mon, 3 Nov 2008 21:13:09 +0000 Subject: Refs #514: Entity and subtype caching git-svn-id: https://code.elgg.org/elgg/trunk@2389 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'engine') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index de1093835..1daa46a00 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -12,10 +12,10 @@ */ /// Cache objects in order to minimise database access. - $ENTITY_CACHE = array(); + $ENTITY_CACHE = NULL; /// Cache subtype searches - $SUBTYPE_CACHE = array(); + $SUBTYPE_CACHE = NULL; /** * ElggEntity The elgg entity superclass @@ -920,8 +920,8 @@ { global $ENTITY_CACHE; - if (!is_array($ENTITY_CACHE)) - $ENTITY_CACHE = array(); + if (!$ENTITY_CACHE) + $ENTITY_CACHE = new ElggStaticVariableCache('entity_cache'); // TODO: Replace with memcache? } /** @@ -935,8 +935,8 @@ $guid = (int)$guid; - unset($ENTITY_CACHE[$guid]); - + //unset($ENTITY_CACHE[$guid]); + $ENTITY_CACHE->delete($guid); } /** @@ -1012,6 +1012,9 @@ $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'); + $SUBTYPE_CACHE[$result->id] = $result; return $result->id; } @@ -1039,6 +1042,9 @@ $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'); + $SUBTYPE_CACHE[$subtype_id] = $result; return $result->subtype; } @@ -1064,6 +1070,9 @@ $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'); + $SUBTYPE_CACHE[$result->id] = $result; return $result->class; } @@ -1090,6 +1099,9 @@ $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'); + $SUBTYPE_CACHE[$subtype_id] = $result; return $result->class; } -- cgit v1.2.3