User: Simplify process cache by using WANObjectCache::getWithSetCallback
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 27 Feb 2016 19:35:21 +0000 (19:35 +0000)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 1 Jun 2016 04:13:08 +0000 (21:13 -0700)
commit3bbccc8da64b65038aed309a03458e064e6dad14
tree29ee6c88619725d6d9c33f834ca2b629bc9fb0a2
parent866924fb00d46004cad587e527915096a3b16d23
User: Simplify process cache by using WANObjectCache::getWithSetCallback

Follows-up 7d67b4d9199c733318.

* Convert loadFromId() to use getWithSetCallback() and centralise
  cache access logic there instead of spread between loadFromCache()
  and saveToCache().

* Remove process cache from User class (added in 9c733318).
  Instead, tell WANObjectCache to process-cache the key for 30 seconds.

* No need to deal with process cache in purge() because load uses slaves by
  default and may be lagged. Reads that require READ_LATEST already bypass
  the cache.

* Remove saveToCache() and move logic to loadFromCache().
  It was technically a public method, but marked private and no longer used
  in any extensions.

* Remove redundant isAnon() check in loadFromCache().
  This is already done by loadFromId() and loadFromDatabase().

* Remove hasOrMadeRecentMasterChanges() check. It was used to add READ_LATEST
  to the flags. However, this check only occurred if either READ_LATEST was
  already set, or after consulting cache. Which means in general, it never
  does anything. If we want to keep this, we should probably move it higher up.

* Let WANObjectCache handle cache version. That way, there is no longer separate
  logic for "populate cache" and "cache lookup failed". Instead, there is
  just "get data" that tries cache first.

  I've considered moving the version into the cache key (like we do elsewhere)
  but that would be problematic here since User cache must be purgeable
  cross-wiki and other wikis may run a different version (either in general,
  or even just during a deployment). As such, the key must remain unchanged when
  the version changes so that purges from newer wikis affect what older wikis see
  and vice versa.

Change-Id: Icfbc54dfd0ea594dd52fc1cfd403a7f66f1dd0b0
includes/user/User.php
tests/phpunit/MediaWikiTestCase.php