MessageCache: derive the hash from the cache contents
authorOri Livneh <ori@wikimedia.org>
Thu, 13 Aug 2015 04:40:49 +0000 (21:40 -0700)
committerOri.livneh <ori@wikimedia.org>
Fri, 14 Aug 2015 19:49:07 +0000 (19:49 +0000)
Follow-up for I020617d, where I got this wrong. It is probable that multiple
application servers will try to build a local cache at the same time, in which
case they will cause the cache key to thrash. It is necessary that two
application servers building a local cache from the database generate the same
hash for a given set of messages.

Change-Id: Ieeefc2094a83be9401c466bec859c1588ddfbcdf

includes/cache/MessageCache.php

index 304c4f2..3f60d8c 100644 (file)
@@ -530,7 +530,8 @@ class MessageCache {
                }
 
                $cache['VERSION'] = MSG_CACHE_VERSION;
-               $cache['HASH'] = wfRandomString( 8 );
+               ksort( $cache );
+               $cache['HASH'] = md5( serialize( $cache ) );
                $cache['EXPIRY'] = wfTimestamp( TS_MW, time() + $this->mExpiry );
 
                return $cache;