From c09c8b4e936d9343e1774afd39f89a38c73e4165 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 1 May 2017 14:51:57 -0700 Subject: [PATCH] config: Use less generic cache key, and not fragmented by wiki * Use makeGlobalKey instead of makeKey to avoid fragmenting the cache by the wiki-specific key space. * Add "EtcdConfig" and $this->host to the cache key to make it less generic and less likely to conflict with unrelated values in case multiple instances exist somewhere in the MediaWiki run time (or during testing/debugging). Adding $this->host should be fine given we were already including the directory within that host. Although I do recognise that we may want to encourage slow cache rollover instead of instance cache rollover in case the host name needs to changed. Perhaps we should have some kind of canonical name for the instance for the purpose of caching so that directory or host can be changed without changing the cache key, and thus have cache roll over normally over the course of 10 seconds, instead of immediately. On the other hand, deployment will likely already spread things out a little bit. In addition, due to the cache being kept indefinitely this means the old key will stay indefinitely. Perhaps not an issue given it's just one key, which will clear on restart eventually? Bug: T156924 Change-Id: I622e6618f2d4171626e4b272bcb11a97a85cb770 --- includes/config/EtcdConfig.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/includes/config/EtcdConfig.php b/includes/config/EtcdConfig.php index f226f17de6..fd5c3f705a 100644 --- a/includes/config/EtcdConfig.php +++ b/includes/config/EtcdConfig.php @@ -54,8 +54,6 @@ class EtcdConfig implements Config, LoggerAwareInterface { private $skewCacheTTL; /** @var integer */ private $timeout; - /** @var string */ - private $directoryHash; /** * @param array $params Parameter map: @@ -81,7 +79,6 @@ class EtcdConfig implements Config, LoggerAwareInterface { $this->host = $params['host']; $this->protocol = $params['protocol']; $this->directory = trim( $params['directory'], '/' ); - $this->directoryHash = sha1( $this->directory ); $this->encoding = $params['encoding']; $this->skewCacheTTL = $params['skewTTL']; $this->baseCacheTTL = max( $params['cacheTTL'] - $this->skewCacheTTL, 0 ); @@ -131,7 +128,11 @@ class EtcdConfig implements Config, LoggerAwareInterface { } $now = microtime( true ); - $key = $this->srvCache->makeKey( 'variable', $this->directoryHash ); + $key = $this->srvCache->makeGlobalKey( + __CLASS__, + $this->host, + $this->directory + ); // Get the cached value or block until it is regenerated (by this or another thread)... $data = null; // latest config info -- 2.20.1