aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorSteve Clay <steve@mrclay.org>2012-08-22 11:44:31 -0400
committerSteve Clay <steve@mrclay.org>2012-08-22 11:44:31 -0400
commitf9c83e896f59dcbb11dc5a876aa71cf581a49afe (patch)
tree8bc3f440f3f29927befadedee3bc92de85b8ff39 /engine
parent08c5f19e78033899544c1651e90ba4da44d93954 (diff)
downloadelgg-f9c83e896f59dcbb11dc5a876aa71cf581a49afe.tar.gz
elgg-f9c83e896f59dcbb11dc5a876aa71cf581a49afe.tar.bz2
Refactored for clarity
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/entities.php26
1 files changed, 15 insertions, 11 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 90e62fac7..b8ebbd68a 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -679,8 +679,10 @@ function entity_row_to_elggstar($row) {
* @link http://docs.elgg.org/DataModel/Entities
*/
function get_entity($guid) {
- static $newentity_cache;
- $new_entity = false;
+ // This should not be a static local var. Notice that cache writing occurs in a completely
+ // different instance outside this function.
+ // @todo We need a single Memcache instance with a shared pool of namespace wrappers. This function would pull an instance from the pool.
+ static $shared_cache;
// We could also use: if (!(int) $guid) { return FALSE },
// but that evaluates to a false positive for $guid = TRUE.
@@ -696,16 +698,18 @@ function get_entity($guid) {
}
// Check shared memory cache, if available
- if ((!$newentity_cache) && (is_memcache_available())) {
- $newentity_cache = new ElggMemcache('new_entity_cache');
- }
-
- if ($newentity_cache) {
- $new_entity = $newentity_cache->load($guid);
+ if (null === $shared_cache) {
+ if (is_memcache_available()) {
+ $shared_cache = new ElggMemcache('new_entity_cache');
+ } else {
+ $shared_cache = false;
+ }
}
-
- if ($new_entity) {
- return $new_entity;
+ if ($shared_cache) {
+ $new_entity = $shared_cache->load($guid);
+ if ($new_entity) {
+ return $new_entity;
+ }
}
$new_entity = entity_row_to_elggstar(get_entity_as_row($guid));