resourceloader: Make sure hashmtime cache key is different by language
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 4 Dec 2013 00:26:16 +0000 (01:26 +0100)
committerCatrope <roan.kattouw@gmail.com>
Wed, 4 Dec 2013 00:56:13 +0000 (00:56 +0000)
We were continuously invalidating the cache for the
ResourceLoaderLanguageDataModule every time a request for a langauge
other than the previous request came in as they all resulted in
the same cache key.

This could be resolved by adding $context->getLang() to the key
(which would be enough for langdata module, but not enough for
other uses of hashmtime), or by adding $context->getHash() (which
will fragment it for all possible context factor combinations,
slightly overkill for most cases, but would work).

Instead resolving it the same way we did in d3bdda3 for a similar
issue in #getDefinitionMtime: by adding the hash itself to the
key. That way it will solve the problem, including two nice things:
* Not fragment anymore than necessary (if it doesn't vary by
  skin, it won't vary by skin, and same for language etc.).
* Always separate keys when the value is different (if something
  can very based on other factors, e.g. LocalSettings globals or
  whatever untracked method may exist for influencing anything,
  it will all work as expected).
* Don't keep alternating and incrementing the timestamp while a
  multi-server infrastructure is syncing code (e.g. old code and
  new code for the same request context will not result in the
  same key and each old/new server alternatingly increasing the
  timestamp, instead the first new server will make the new key
  and the other servers will gradually start finding the new key
  with the timestamp of when it was first seen).

Change-Id: Ifa9088c11c388ca6c912e62efc43494e91702603

includes/resourceloader/ResourceLoaderModule.php

index db84dcf..429bcec 100644 (file)
@@ -408,7 +408,7 @@ abstract class ResourceLoaderModule {
                }
 
                $cache = wfGetCache( CACHE_ANYTHING );
-               $key = wfMemcKey( 'resourceloader', 'modulemodifiedhash', $this->getName() );
+               $key = wfMemcKey( 'resourceloader', 'modulemodifiedhash', $this->getName(), $hash );
 
                $data = $cache->get( $key );
                if ( is_array( $data ) && $data['hash'] === $hash ) {