obectcache: split out some WAN cache refresh logic into scheduleAsyncRefresh()
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 28 Feb 2019 01:13:40 +0000 (17:13 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 28 Feb 2019 01:13:40 +0000 (17:13 -0800)
Change-Id: If5f895a0d38cd0d6861125000df4fcfc66f1eeb3

includes/libs/objectcache/WANObjectCache.php

index 976c176..0480d71 100644 (file)
@@ -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
         *