diff options
author | Steve Clay <steve@mrclay.org> | 2012-11-28 16:05:35 -0500 |
---|---|---|
committer | Steve Clay <steve@mrclay.org> | 2012-11-28 16:05:35 -0500 |
commit | 87b2da7e3d8f06ba541fea29d44c4c2e9630584d (patch) | |
tree | f814784096c38f0e2d790691c8812e92f0152116 | |
parent | d87c0ce422debe2a5b986a55b66c4b804c4b5927 (diff) | |
download | elgg-87b2da7e3d8f06ba541fea29d44c4c2e9630584d.tar.gz elgg-87b2da7e3d8f06ba541fea29d44c4c2e9630584d.tar.bz2 |
Fixes #4937: Metadata cache is purged when entity cache item removed
-rw-r--r-- | engine/lib/entities.php | 10 |
1 files changed, 9 insertions, 1 deletions
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; |