]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Add way to ban entities from the entity cache
authorSteve Clay <steve@mrclay.org>
Fri, 7 Jun 2013 13:43:12 +0000 (09:43 -0400)
committerSteve Clay <steve@mrclay.org>
Fri, 7 Jun 2013 13:43:12 +0000 (09:43 -0400)
engine/lib/entities.php

index 5cfeca6f8aa547b95c72762e70b4257b0dbffcf8..ac4b4d99546bd371bb99dee18189a8bc0d4d6ccc 100644 (file)
 global $ENTITY_CACHE;
 $ENTITY_CACHE = array();
 
+/**
+ * GUIDs of entities banned from the entity cache (during this request)
+ *
+ * @global array $ENTITY_CACHE_BANNED_GUIDS
+ * @access private
+ */
+global $ENTITY_CACHE_BANNED_GUIDS;
+$ENTITY_CACHE_BANNED_GUIDS = array();
+
 /**
  * Cache subtypes and related class names.
  *
@@ -25,6 +34,34 @@ $ENTITY_CACHE = array();
 global $SUBTYPE_CACHE;
 $SUBTYPE_CACHE = null;
 
+/**
+ * Ban this entity from the entity cache
+ *
+ * @param int $guid The entity guid
+ *
+ * @access private
+ * @todo this is a workaround until #5604 can be implemented
+ */
+function _elgg_ban_caching_for_entity($guid) {
+       global $ENTITY_CACHE_BANNED_GUIDS;
+
+       _elgg_invalidate_cache_for_entity($guid);
+       $ENTITY_CACHE_BANNED_GUIDS[$guid] = true;
+}
+
+/**
+ * Allow this entity to be stored in the entity cache
+ *
+ * @param int $guid The entity guid
+ *
+ * @access private
+ */
+function _elgg_unban_caching_for_entity($guid) {
+       global $ENTITY_CACHE_BANNED_GUIDS;
+
+       unset($ENTITY_CACHE_BANNED_GUIDS[$guid]);
+}
+
 /**
  * Invalidate this class's entry in the cache.
  *
@@ -57,7 +94,7 @@ function _elgg_invalidate_cache_for_entity($guid) {
  * @todo Use an ElggCache object
  */
 function _elgg_cache_entity(ElggEntity $entity) {
-       global $ENTITY_CACHE;
+       global $ENTITY_CACHE, $ENTITY_CACHE_BANNED_GUIDS;
 
        // Don't cache non-plugin entities while access control is off, otherwise they could be
        // exposed to users who shouldn't see them when control is re-enabled.
@@ -65,6 +102,11 @@ function _elgg_cache_entity(ElggEntity $entity) {
                return;
        }
 
+       $guid = $entity->getGUID();
+       if (isset($ENTITY_CACHE_BANNED_GUIDS[$guid])) {
+               return;
+       }
+
        // Don't store too many or we'll have memory problems
        // @todo Pick a less arbitrary limit
        if (count($ENTITY_CACHE) > 256) {
@@ -79,7 +121,7 @@ function _elgg_cache_entity(ElggEntity $entity) {
                elgg_get_metadata_cache()->clear($random_guid);
        }
 
-       $ENTITY_CACHE[$entity->guid] = $entity;
+       $ENTITY_CACHE[$guid] = $entity;
 }
 
 /**