diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-11-03 21:13:09 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-11-03 21:13:09 +0000 |
commit | e9a37af94c1cb294f561305c94d4e00e0bc49990 (patch) | |
tree | 466b58f823aad2478cb851a7c8cbed31732a0679 | |
parent | 3156139c506eb9d78bfdba13395f1f0f7795d8a1 (diff) | |
download | elgg-e9a37af94c1cb294f561305c94d4e00e0bc49990.tar.gz elgg-e9a37af94c1cb294f561305c94d4e00e0bc49990.tar.bz2 |
Refs #514: Entity and subtype caching
git-svn-id: https://code.elgg.org/elgg/trunk@2389 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/entities.php | 24 |
1 files changed, 18 insertions, 6 deletions
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; } |