objectcache: Remove getWithSetCallback() signature backwards-compatability
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 17 Oct 2015 22:45:08 +0000 (15:45 -0700)
committerKrinkle <krinklemail@gmail.com>
Mon, 19 Oct 2015 23:47:04 +0000 (23:47 +0000)
All callers have been migrated

Change-Id: I7b6b87594dd724434ba24d8206fe07d66c1d5d25

includes/libs/objectcache/WANObjectCache.php
tests/phpunit/includes/objectcache/WANObjectCacheTest.php

index 3b9c832..e68740e 100644 (file)
@@ -656,26 +656,9 @@ class WANObjectCache {
         *      since the callback should use slave DBs and they may be lagged or have snapshot
         *      isolation anyway, this should not typically matter.
         *      Default: WANObjectCache::TTL_UNCACHEABLE.
-        * @param array $oldOpts Unused (mentioned only to avoid PHPDoc warnings)
         * @return mixed Value to use for the key
         */
-       final public function getWithSetCallback(
-               $key, $ttl, $callback, array $opts = array(), $oldOpts = array()
-       ) {
-               // Back-compat with 1.26: Swap $ttl and $callback
-               if ( is_int( $callback ) ) {
-                       $temp = $ttl;
-                       $ttl = $callback;
-                       $callback = $temp;
-               }
-               // Back-compat with 1.26: $checkKeys as separate parameter
-               if ( $oldOpts || ( is_array( $opts ) && isset( $opts[0] ) ) ) {
-                       $checkKeys = $opts;
-                       $opts = $oldOpts;
-               } else {
-                       $checkKeys = isset( $opts['checkKeys'] ) ? $opts['checkKeys'] : array();
-               }
-
+       final public function getWithSetCallback( $key, $ttl, $callback, array $opts = array() ) {
                $pcTTL = isset( $opts['pcTTL'] ) ? $opts['pcTTL'] : self::TTL_UNCACHEABLE;
 
                // Try the process cache if enabled
@@ -683,7 +666,7 @@ class WANObjectCache {
 
                if ( $value === false ) {
                        // Fetch the value over the network
-                       $value = $this->doGetWithSetCallback( $key, $ttl, $callback, $checkKeys, $opts );
+                       $value = $this->doGetWithSetCallback( $key, $ttl, $callback, $opts );
                        // Update the process cache if enabled
                        if ( $pcTTL >= 0 && $value !== false ) {
                                $this->procCache->set( $key, $value, $pcTTL );
@@ -701,15 +684,13 @@ class WANObjectCache {
         * @param string $key
         * @param integer $ttl
         * @param callback $callback
-        * @param array $checkKeys
         * @param array $opts
         * @return mixed
         */
-       protected function doGetWithSetCallback(
-               $key, $ttl, $callback, array $checkKeys, array $opts
-       ) {
+       protected function doGetWithSetCallback( $key, $ttl, $callback, array $opts ) {
                $lowTTL = isset( $opts['lowTTL'] ) ? $opts['lowTTL'] : min( self::LOW_TTL, $ttl );
                $lockTSE = isset( $opts['lockTSE'] ) ? $opts['lockTSE'] : self::TSE_NONE;
+               $checkKeys = isset( $opts['checkKeys'] ) ? $opts['checkKeys'] : array();
 
                // Get the current key value
                $curTTL = null;
index 8981f2f..c3702c5 100644 (file)
@@ -3,6 +3,8 @@
 class WANObjectCacheTest extends MediaWikiTestCase {
        /** @var WANObjectCache */
        private $cache;
+       /**@var BagOStuff */
+       private $internalCache;
 
        protected function setUp() {
                parent::setUp();
@@ -104,7 +106,7 @@ class WANObjectCacheTest extends MediaWikiTestCase {
                };
 
                $wasSet = 0;
-               $v = $cache->getWithSetCallback( $key, $func, 30, array(), array( 'lockTSE' => 5 ) );
+               $v = $cache->getWithSetCallback( $key, 30, $func, array( 'lockTSE' => 5 ) );
                $this->assertEquals( $value, $v, "Value returned" );
                $this->assertEquals( 1, $wasSet, "Value regenerated" );
 
@@ -114,7 +116,7 @@ class WANObjectCacheTest extends MediaWikiTestCase {
                $this->assertGreaterThanOrEqual( 19, $curTTL, 'Current TTL between 19-20 (overriden)' );
 
                $wasSet = 0;
-               $v = $cache->getWithSetCallback( $key, $func, 30, array(), array(
+               $v = $cache->getWithSetCallback( $key, 30, $func, array(
                        'lowTTL' => 0,
                        'lockTSE' => 5,
                ) );
@@ -124,7 +126,8 @@ class WANObjectCacheTest extends MediaWikiTestCase {
                $priorTime = microtime( true );
                usleep( 1 );
                $wasSet = 0;
-               $v = $cache->getWithSetCallback( $key, $func, 30, array( $cKey1, $cKey2 ) );
+               $v = $cache->getWithSetCallback( $key, 30, $func,
+                       array( 'checkKeys' => array( $cKey1, $cKey2 ) ) );
                $this->assertEquals( $value, $v, "Value returned" );
                $this->assertEquals( 1, $wasSet, "Value regenerated due to check keys" );
                $t1 = $cache->getCheckKeyTime( $cKey1 );
@@ -134,7 +137,8 @@ class WANObjectCacheTest extends MediaWikiTestCase {
 
                $priorTime = microtime( true );
                $wasSet = 0;
-               $v = $cache->getWithSetCallback( $key, $func, 30, array( $cKey1, $cKey2 ) );
+               $v = $cache->getWithSetCallback( $key, 30, $func,
+                       array( 'checkKeys' => array( $cKey1, $cKey2 ) ) );
                $this->assertEquals( $value, $v, "Value returned" );
                $this->assertEquals( 1, $wasSet, "Value regenerated due to still-recent check keys" );
                $t1 = $cache->getCheckKeyTime( $cKey1 );
@@ -149,10 +153,10 @@ class WANObjectCacheTest extends MediaWikiTestCase {
 
                $wasSet = 0;
                $key = wfRandomString();
-               $v = $cache->getWithSetCallback( $key, $func, 30, array(), array( 'pcTTL' => 5 ) );
+               $v = $cache->getWithSetCallback( $key, 30, $func, array( 'pcTTL' => 5 ) );
                $this->assertEquals( $value, $v, "Value returned" );
                $cache->delete( $key );
-               $v = $cache->getWithSetCallback( $key, $func, 30, array(), array( 'pcTTL' => 5 ) );
+               $v = $cache->getWithSetCallback( $key, 30, $func, array( 'pcTTL' => 5 ) );
                $this->assertEquals( $value, $v, "Value still returned after deleted" );
                $this->assertEquals( 1, $wasSet, "Value process cached while deleted" );
        }
@@ -172,13 +176,13 @@ class WANObjectCacheTest extends MediaWikiTestCase {
                };
 
                $cache->delete( $key );
-               $ret = $cache->getWithSetCallback( $key, 30, $func, array(), array( 'lockTSE' => 5 ) );
+               $ret = $cache->getWithSetCallback( $key, 30, $func, array( 'lockTSE' => 5 ) );
                $this->assertEquals( $value, $ret );
                $this->assertEquals( 1, $calls, 'Value was populated' );
 
                // Acquire a lock to verify that getWithSetCallback uses lockTSE properly
                $this->internalCache->lock( $key, 0 );
-               $ret = $cache->getWithSetCallback( $key, 30, $func, array(), array( 'lockTSE' => 5 ) );
+               $ret = $cache->getWithSetCallback( $key, 30, $func, array( 'lockTSE' => 5 ) );
                $this->assertEquals( $value, $ret );
                $this->assertEquals( 1, $calls, 'Callback was not used' );
        }