From 178d312eb80718c148e3e5774d116358c6e302f8 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 27 Aug 2019 16:35:49 +0100 Subject: [PATCH] MessageCache: Remove $wgMsgCacheExpiry configuration var This variable has never been set to anything other than the default value of 24 hours as introduced in 2003 (r2203, r2204; or 036ff960ce, edf6b38626). The variable has never changed in core, it's not overridden at WMF, and MessageCache is not constructed anywhere other than ServiceWiring.php anywhere in repos on Wikimedia Gerrit, indexed by MediaWiki Codesearch, or any GitHub-hosted repository (incl Wikia repos and WikiHow mirrors). I've also checked all GitHub-hosted repos for boilerplates and/or public settings files from devs or prod, and couldn't find any example of this being overridden (after filtering out copies of the core files themselves). Rather than having to support potentially hard-to-predict interactions betweeen caching layers by checking its state, make it a constant so we can code reason about it more easily. Change-Id: Ie2e139001aae3ac54b509d94a3d917bb408eaca0 --- RELEASE-NOTES-1.34 | 2 ++ docs/memcached.txt | 8 +------- includes/DefaultSettings.php | 7 ------- includes/ServiceWiring.php | 1 - includes/cache/MessageCache.php | 21 +++++++++------------ 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/RELEASE-NOTES-1.34 b/RELEASE-NOTES-1.34 index df25d30c59..7cf1c02176 100644 --- a/RELEASE-NOTES-1.34 +++ b/RELEASE-NOTES-1.34 @@ -75,6 +75,8 @@ For notes on 1.33.x and older releases, see HISTORY. * $wgDebugPrintHttpHeaders - The default of including HTTP headers in the debug log channel is no longer configurable. The debug log itself remains configurable via $wgDebugLogFile. +* $wgMsgCacheExpiry - The MessageCache uses 24 hours as the expiry for values + stored in WANObjectCache. This is no longer configurable. * $wgPasswordSalt – This setting, used for migrating exceptionally old, insecure password setups and deprecated since 1.24, is now removed. * $wgDBOracleDRCP - If you must use persistent connections, set DBO_PERSISTENT diff --git a/docs/memcached.txt b/docs/memcached.txt index ba325fe672..d0a6e3dedd 100644 --- a/docs/memcached.txt +++ b/docs/memcached.txt @@ -131,13 +131,7 @@ Localisation: cleared by: Language::loadLocalisation() Message Cache: - backend: $wgMessageCacheType - key: $wgDBname:messages, $wgDBname:messages-hash, $wgDBname:messages-status - ex: wikidb:messages, wikidb:messages-hash, wikidb:messages-status - stores: an array where the keys are DB keys and the values are messages - set in: wfMessage(), Article::editUpdates() and Title::moveTo() - expiry: $wgMsgCacheExpiry - cleared by: nothing + See MessageCache.php. Newtalk: key: $wgDBname:newtalk:ip:$ip diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 554a2d50e4..b1d7b3a569 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3120,13 +3120,6 @@ $wgTranslateNumerals = true; */ $wgUseDatabaseMessages = true; -/** - * Expiry time for the message cache key, in seconds. - * - * @var int Defaults to 24 hours. - */ -$wgMsgCacheExpiry = 86400; - /** * Maximum entry size in the message cache, in bytes */ diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 21a66cde88..78609e56ea 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -403,7 +403,6 @@ return [ ? $services->getLocalServerObjectCache() : new EmptyBagOStuff(), $mainConfig->get( 'UseDatabaseMessages' ), - $mainConfig->get( 'MsgCacheExpiry' ), $services->getContentLanguage() ); }, diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index c2913e5cb7..661ab87a6c 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -45,6 +45,12 @@ class MessageCache { /** How long memcached locks last */ const LOCK_TTL = 30; + /** + * Lifetime for cache, for keys stored in $wanCache, in seconds. + * @var int + */ + const WAN_TTL = IExpiringStore::TTL_DAY; + /** * Process cache of loaded messages that are defined in MediaWiki namespace * @@ -70,12 +76,6 @@ class MessageCache { */ protected $mDisable; - /** - * Lifetime for cache, used by object caching. - * Set on construction, see __construct(). - */ - protected $mExpiry; - /** * Message cache has its own parser which it uses to transform messages * @var ParserOptions @@ -137,7 +137,6 @@ class MessageCache { * @param BagOStuff $clusterCache * @param BagOStuff $serverCache * @param bool $useDB Whether to look for message overrides (e.g. MediaWiki: pages) - * @param int $expiry Lifetime for cache. @see $mExpiry. * @param Language|null $contLang Content language of site */ public function __construct( @@ -145,7 +144,6 @@ class MessageCache { BagOStuff $clusterCache, BagOStuff $serverCache, $useDB, - $expiry, Language $contLang = null ) { $this->wanCache = $wanCache; @@ -155,7 +153,6 @@ class MessageCache { $this->cache = new MapCacheLRU( 5 ); // limit size for sanity $this->mDisable = !$useDB; - $this->mExpiry = $expiry; $this->contLang = $contLang ?? MediaWikiServices::getInstance()->getContentLanguage(); } @@ -551,7 +548,7 @@ class MessageCache { # messages larger than $wgMaxMsgCacheEntrySize, since those are only # stored and fetched from memcache. $cache['HASH'] = md5( serialize( $cache ) ); - $cache['EXPIRY'] = wfTimestamp( TS_MW, time() + $this->mExpiry ); + $cache['EXPIRY'] = wfTimestamp( TS_MW, time() + self::WAN_TTL ); unset( $cache['EXCESSIVE'] ); // only needed for hash return $cache; @@ -666,7 +663,7 @@ class MessageCache { $this->wanCache->set( $this->bigMessageCacheKey( $cache['HASH'], $title ), ' ' . $newTextByTitle[$title], - $this->mExpiry + self::WAN_TTL ); } // Mark this cache as definitely being "latest" (non-volatile) so @@ -1094,7 +1091,7 @@ class MessageCache { function () use ( $code, $dbKey, $hash, $fname ) { return $this->wanCache->getWithSetCallback( $this->bigMessageCacheKey( $hash, $dbKey ), - $this->mExpiry, + self::WAN_TTL, function ( $oldValue, &$ttl, &$setOpts ) use ( $dbKey, $code, $fname ) { // Try loading the message from the database $dbr = wfGetDB( DB_REPLICA ); -- 2.20.1