parent::setUp();
$this->cache = new WANObjectCache( [
- 'cache' => new HashBagOStuff(),
- 'pool' => 'testcache-hash',
- 'relayer' => new EventRelayerNull( [] )
+ 'cache' => new HashBagOStuff()
] );
$wanCache = TestingAccessWrapper::newFromObject( $this->cache );
$priorAsOf = null;
$wasSet = 0;
$func = function ( $old, &$ttl, &$opts, $asOf )
- use ( &$wasSet, &$priorValue, &$priorAsOf, $value )
- {
+ use ( &$wasSet, &$priorValue, &$priorAsOf, $value ) {
++$wasSet;
$priorValue = $old;
$priorAsOf = $asOf;
return $value;
};
+ $mockWallClock = 1549343530.2053;
+ $priorTime = $mockWallClock; // reference time
+ $cache->setMockTime( $mockWallClock );
+
$wasSet = 0;
$v = $cache->getWithSetCallback( $key, 30, $func, [ 'lockTSE' => 5 ] + $extOpts );
$this->assertEquals( $value, $v, "Value returned" );
$this->assertEquals( $value, $v, "Value returned" );
$this->assertEquals( 0, $wasSet, "Value not regenerated" );
- $mockWallClock = microtime( true );
- $priorTime = $mockWallClock; // reference time
- $cache->setMockTime( $mockWallClock );
-
$mockWallClock += 1;
$wasSet = 0;
return 'xxx' . $wasSet;
};
- $mockWallClock = microtime( true );
+ $mockWallClock = 1549343530.2053;
$priorTime = $mockWallClock; // reference time
$wasSet = 0;
$this->assertEquals( 'xxx1', $v, "Value still returned after expired (in grace)" );
$this->assertEquals( 1, $wasSet, "Value still returned after expired (in grace)" );
- // Change of refresh increase to unity as staleness approaches graceTTL
+ // Chance of refresh increase to unity as staleness approaches graceTTL
$mockWallClock += $cache::TTL_WEEK; // 8 days of being stale
$v = $cache->getWithSetCallback(
$key,
$this->assertNotEquals( null, $oldAsOfReceived, "Callback got post-grace stale value" );
}
+ /**
+ * @dataProvider getWithSetCallback_provider
+ * @covers WANObjectCache::getWithSetCallback()
+ * @covers WANObjectCache::doGetWithSetCallback()
+ * @param array $extOpts
+ * @param bool $versioned
+ */
+ function testGetWithSetcallback_touched( array $extOpts, $versioned ) {
+ $cache = $this->cache;
+
+ $mockWallClock = 1549343530.2053;
+ $cache->setMockTime( $mockWallClock );
+
+ $checkFunc = function ( $oldVal, &$ttl, array $setOpts, $oldAsOf )
+ use ( &$wasSet ) {
+ ++$wasSet;
+
+ return 'xxx' . $wasSet;
+ };
+
+ $key = wfRandomString();
+ $wasSet = 0;
+ $touched = null;
+ $touchedCallback = function () use ( &$touched ) {
+ return $touched;
+ };
+ $v = $cache->getWithSetCallback(
+ $key,
+ $cache::TTL_INDEFINITE,
+ $checkFunc,
+ [ 'touchedCallback' => $touchedCallback ] + $extOpts
+ );
+ $mockWallClock += 60;
+ $v = $cache->getWithSetCallback(
+ $key,
+ $cache::TTL_INDEFINITE,
+ $checkFunc,
+ [ 'touchedCallback' => $touchedCallback ] + $extOpts
+ );
+ $this->assertEquals( 'xxx1', $v, "Value was computed once" );
+ $this->assertEquals( 1, $wasSet, "Value was computed once" );
+
+ $touched = $mockWallClock - 10;
+ $v = $cache->getWithSetCallback(
+ $key,
+ $cache::TTL_INDEFINITE,
+ $checkFunc,
+ [ 'touchedCallback' => $touchedCallback ] + $extOpts
+ );
+ $v = $cache->getWithSetCallback(
+ $key,
+ $cache::TTL_INDEFINITE,
+ $checkFunc,
+ [ 'touchedCallback' => $touchedCallback ] + $extOpts
+ );
+ $this->assertEquals( 'xxx2', $v, "Value was recomputed once" );
+ $this->assertEquals( 2, $wasSet, "Value was recomputed once" );
+ }
+
public static function getWithSetCallback_provider() {
return [
[ [], false ],
};
$cache = new NearExpiringWANObjectCache( [
- 'cache' => new HashBagOStuff(),
- 'pool' => 'empty',
+ 'cache' => new HashBagOStuff()
] );
$wasSet = 0;
};
$cache = new NearExpiringWANObjectCache( [
'cache' => new HashBagOStuff(),
- 'pool' => 'empty',
'asyncHandler' => $asyncHandler
] );
- $mockWallClock = microtime( true );
+ $mockWallClock = 1549343530.2053;
$priorTime = $mockWallClock; // reference time
$cache->setMockTime( $mockWallClock );
$this->assertEquals( $value, $v, "New value stored" );
$cache = new PopularityRefreshingWANObjectCache( [
- 'cache' => new HashBagOStuff(),
- 'pool' => 'empty'
+ 'cache' => new HashBagOStuff()
] );
$mockWallClock = $priorTime;
return "@$id$";
};
+ $mockWallClock = 1549343530.2053;
+ $priorTime = $mockWallClock; // reference time
+ $cache->setMockTime( $mockWallClock );
+
$wasSet = 0;
$keyedIds = new ArrayIterator( [ $keyA => 3353 ] );
$value = "@3353$";
$this->assertEquals( 1, $wasSet, "Value not regenerated" );
$this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in process cache" );
- $mockWallClock = microtime( true );
- $priorTime = $mockWallClock; // reference time
- $cache->setMockTime( $mockWallClock );
-
$mockWallClock += 1;
$wasSet = 0;
WANObjectCache::VALUE_KEY_PREFIX . 'k1' => 'val-id1',
WANObjectCache::VALUE_KEY_PREFIX . 'k2' => 'val-id2'
] );
- $wanCache = new WANObjectCache( [ 'cache' => $localBag, 'pool' => 'testcache-hash' ] );
+ $wanCache = new WANObjectCache( [ 'cache' => $localBag ] );
// Warm the process cache
$keyedIds = new ArrayIterator( [ 'k1' => 'id1', 'k2' => 'id2' ] );
return $newValues;
};
+ $mockWallClock = 1549343530.2053;
+ $priorTime = $mockWallClock; // reference time
+ $cache->setMockTime( $mockWallClock );
+
$wasSet = 0;
$keyedIds = new ArrayIterator( [ $keyA => 3353 ] );
$value = "@3353$";
$this->assertEquals( 1, $wasSet, "Value not regenerated" );
$this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in process cache" );
- $mockWallClock = microtime( true );
- $priorTime = $mockWallClock; // reference time
- $cache->setMockTime( $mockWallClock );
-
$mockWallClock += 1;
$wasSet = 0;
$key2 = wfRandomString();
$key3 = wfRandomString();
+ $mockWallClock = 1549343530.2053;
+ $priorTime = $mockWallClock; // reference time
+ $cache->setMockTime( $mockWallClock );
+
$cache->set( $key1, $value1, 5 );
$cache->set( $key2, $value2, 10 );
$cKey1 = wfRandomString();
$cKey2 = wfRandomString();
- $mockWallClock = microtime( true );
- $priorTime = $mockWallClock; // reference time
- $cache->setMockTime( $mockWallClock );
-
$mockWallClock += 1;
$curTTLs = [];
$value1 = wfRandomString();
$value2 = wfRandomString();
- $mockWallClock = microtime( true );
+ $mockWallClock = 1549343530.2053;
$cache->setMockTime( $mockWallClock );
// Fake initial check key to be set in the past. Otherwise we'd have to sleep for
$cache = $this->cache;
$key = wfRandomString();
- $mockWallClock = microtime( true );
+ $mockWallClock = 1549343530.2053;
$priorTime = $mockWallClock; // reference time
$cache->setMockTime( $mockWallClock );
$tKey2 = wfRandomString();
$value = 'meow';
+ $mockWallClock = 1549343530.2053;
+ $priorTime = $mockWallClock; // reference time
+ $this->cache->setMockTime( $mockWallClock );
+
// Two check keys are newer (given hold-off) than $key, another is older
$this->internalCache->set(
WANObjectCache::TIME_KEY_PREFIX . $tKey2,
- WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 3 )
+ WANObjectCache::PURGE_VAL_PREFIX . ( $priorTime - 3 )
);
$this->internalCache->set(
WANObjectCache::TIME_KEY_PREFIX . $tKey2,
- WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 5 )
+ WANObjectCache::PURGE_VAL_PREFIX . ( $priorTime - 5 )
);
$this->internalCache->set(
WANObjectCache::TIME_KEY_PREFIX . $tKey1,
- WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 30 )
+ WANObjectCache::PURGE_VAL_PREFIX . ( $priorTime - 30 )
);
$this->cache->set( $key, $value, 30 );
->willReturn( false );
$wanCache = new WANObjectCache( [
- 'cache' => $backend,
- 'pool' => 'testcache-hash',
- 'relayer' => new EventRelayerNull( [] )
+ 'cache' => $backend
] );
$isStale = null;
$localBag->expects( $this->never() )->method( 'delete' );
$wanCache = new WANObjectCache( [
'cache' => $localBag,
- 'pool' => 'testcache-hash',
- 'relayer' => new EventRelayerNull( [] ),
'mcrouterAware' => true,
'region' => 'pmtpa',
'cluster' => 'mw-wan'
->setMethods( [ 'set' ] )->getMock();
$wanCache = new WANObjectCache( [
'cache' => $localBag,
- 'pool' => 'testcache-hash',
- 'relayer' => new EventRelayerNull( [] ),
'mcrouterAware' => true,
'region' => 'pmtpa',
'cluster' => 'mw-wan'
->setMethods( [ 'set' ] )->getMock();
$wanCache = new WANObjectCache( [
'cache' => $localBag,
- 'pool' => 'testcache-hash',
- 'relayer' => new EventRelayerNull( [] ),
'mcrouterAware' => true,
'region' => 'pmtpa',
'cluster' => 'mw-wan'
->setMethods( [ 'delete' ] )->getMock();
$wanCache = new WANObjectCache( [
'cache' => $localBag,
- 'pool' => 'testcache-hash',
- 'relayer' => new EventRelayerNull( [] ),
'mcrouterAware' => true,
'region' => 'pmtpa',
'cluster' => 'mw-wan'
public function testEpoch() {
$bag = new HashBagOStuff();
- $cache = new WANObjectCache( [ 'cache' => $bag, 'pool' => 'testcache-hash' ] );
+ $cache = new WANObjectCache( [ 'cache' => $bag ] );
$key = $cache->makeGlobalKey( 'The whole of the Law' );
$now = microtime( true );
$cache = new WANObjectCache( [
'cache' => $bag,
- 'pool' => 'testcache-hash',
'epoch' => $now - 3600
] );
$cache->setMockTime( $now );
$now += 30;
$cache = new WANObjectCache( [
'cache' => $bag,
- 'pool' => 'testcache-hash',
'epoch' => $now + 3600
] );
$cache->setMockTime( $now );
->willReturn( 'special' );
$wanCache = new WANObjectCache( [
- 'cache' => $backend,
- 'pool' => 'testcache-hash',
- 'relayer' => new EventRelayerNull( [] )
+ 'cache' => $backend
] );
$this->assertSame( 'special', $wanCache->makeKey( 'a', 'b' ) );
->willReturn( 'special' );
$wanCache = new WANObjectCache( [
- 'cache' => $backend,
- 'pool' => 'testcache-hash',
- 'relayer' => new EventRelayerNull( [] )
+ 'cache' => $backend
] );
$this->assertSame( 'special', $wanCache->makeGlobalKey( 'a', 'b' ) );
*/
public function testStatsKeyClass( $key, $class ) {
$wanCache = TestingAccessWrapper::newFromObject( new WANObjectCache( [
- 'cache' => new HashBagOStuff,
- 'pool' => 'testcache-hash',
- 'relayer' => new EventRelayerNull( [] )
+ 'cache' => new HashBagOStuff
] ) );
$this->assertEquals( $class, $wanCache->determineKeyClass( $key ) );