From 87b2da7e3d8f06ba541fea29d44c4c2e9630584d Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Wed, 28 Nov 2012 16:05:35 -0500 Subject: Fixes #4937: Metadata cache is purged when entity cache item removed --- engine/lib/entities.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'engine/lib/entities.php') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index a1c1c2997..e9c96a596 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -68,7 +68,15 @@ function cache_entity(ElggEntity $entity) { // Don't store too many or we'll have memory problems // TODO(evan): Pick a less arbitrary limit if (count($ENTITY_CACHE) > 256) { - unset($ENTITY_CACHE[array_rand($ENTITY_CACHE)]); + $random_guid = array_rand($ENTITY_CACHE); + + unset($ENTITY_CACHE[$random_guid]); + + // Purge separate metadata cache. Original idea was to do in entity destructor, but that would + // have caused a bunch of unnecessary purges at every shutdown. Doing it this way we have no way + // to know that the expunged entity will be GCed (might be another reference living), but that's + // OK; the metadata will reload if necessary. + elgg_get_metadata_cache()->clear($random_guid); } $ENTITY_CACHE[$entity->guid] = $entity; -- cgit v1.2.3