diff options
author | Steve Clay <steve@mrclay.org> | 2012-08-22 11:44:31 -0400 |
---|---|---|
committer | Steve Clay <steve@mrclay.org> | 2012-08-22 11:44:31 -0400 |
commit | f9c83e896f59dcbb11dc5a876aa71cf581a49afe (patch) | |
tree | 8bc3f440f3f29927befadedee3bc92de85b8ff39 /engine/lib/entities.php | |
parent | 08c5f19e78033899544c1651e90ba4da44d93954 (diff) | |
download | elgg-f9c83e896f59dcbb11dc5a876aa71cf581a49afe.tar.gz elgg-f9c83e896f59dcbb11dc5a876aa71cf581a49afe.tar.bz2 |
Refactored for clarity
Diffstat (limited to 'engine/lib/entities.php')
-rw-r--r-- | engine/lib/entities.php | 26 |
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)); |