From 6ee5cdd10b2d88761f26b2a41c9dd300e9db8206 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 27 Feb 2019 17:13:40 -0800 Subject: [PATCH] obectcache: split out some WAN cache refresh logic into scheduleAsyncRefresh() Change-Id: If5f895a0d38cd0d6861125000df4fcfc66f1eeb3 --- includes/libs/objectcache/WANObjectCache.php | 30 +++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 976c176203..0480d71ba9 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -1271,13 +1271,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface { $this->stats->increment( "wanobjectcache.$kClass.hit.good" ); return $value; - } elseif ( $this->asyncHandler ) { - // Update the cache value later, such during post-send of an HTTP request - $func = $this->asyncHandler; - $func( function () use ( $key, $ttl, $callback, $opts, $asOf ) { - $opts['minAsOf'] = INF; // force a refresh - $this->doGetWithSetCallback( $key, $ttl, $callback, $opts, $asOf ); - } ); + } elseif ( $this->scheduleAsyncRefresh( $key, $ttl, $callback, $opts ) ) { $this->stats->increment( "wanobjectcache.$kClass.hit.refresh" ); return $value; @@ -2012,6 +2006,28 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface { return $ok; } + /** + * @param string $key + * @param int $ttl + * @param callable $callback + * @param array $opts + * @return bool Success + */ + private function scheduleAsyncRefresh( $key, $ttl, $callback, $opts ) { + if ( !$this->asyncHandler ) { + return false; + } + // Update the cache value later, such during post-send of an HTTP request + $func = $this->asyncHandler; + $func( function () use ( $key, $ttl, $callback, $opts ) { + $asOf = null; // unused + $opts['minAsOf'] = INF; // force a refresh + $this->doGetWithSetCallback( $key, $ttl, $callback, $opts, $asOf ); + } ); + + return true; + } + /** * Check if a key is fresh or in the grace window and thus due for randomized reuse * -- 2.20.1