* 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
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 );
* @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;
class WANObjectCacheTest extends MediaWikiTestCase {
/** @var WANObjectCache */
private $cache;
+ /**@var BagOStuff */
+ private $internalCache;
protected function setUp() {
parent::setUp();
};
$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" );
$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,
) );
$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 );
$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 );
$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" );
}
};
$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' );
}