* @param int $ttl
*/
public function testSetAndGet( $value, $ttl ) {
+ $cache = $this->cache;
+
$curTTL = null;
$asOf = null;
- $key = $this->cache->makeKey( 'x', wfRandomString() );
+ $key = $cache->makeKey( 'x', wfRandomString() );
- $this->cache->get( $key, $curTTL, [], $asOf );
+ $cache->get( $key, $curTTL, [], $asOf );
$this->assertNull( $curTTL, "Current TTL is null" );
$this->assertNull( $asOf, "Current as-of-time is infinite" );
$t = microtime( true );
- $this->cache->set( $key, $value, $ttl );
- $this->assertEquals( $value, $this->cache->get( $key, $curTTL, [], $asOf ) );
+ $cache->set( $key, $value, $cache::TTL_UNCACHEABLE );
+ $cache->get( $key, $curTTL, [], $asOf );
+ $this->assertNull( $curTTL, "Current TTL is null (TTL_UNCACHEABLE)" );
+ $this->assertNull( $asOf, "Current as-of-time is infinite (TTL_UNCACHEABLE)" );
+
+ $cache->set( $key, $value, $ttl );
+
+ $this->assertEquals( $value, $cache->get( $key, $curTTL, [], $asOf ) );
if ( is_infinite( $ttl ) || $ttl == 0 ) {
$this->assertTrue( is_infinite( $curTTL ), "Current TTL is infinite" );
} else {
$this->assertEquals( 6, $hit, "New values cached" );
foreach ( $keys as $i => $key ) {
- // Should evict from process cache
+ // Should not evict from process cache
$this->cache->delete( $key );
$mockWallClock += 0.001; // cached values will be newer than tombstone
// Get into cache (specific process cache group)
/**
* @dataProvider getWithSetCallback_provider
* @covers WANObjectCache::getWithSetCallback()
- * @covers WANObjectCache::doGetWithSetCallback()
+ * @covers WANObjectCache::fetchOrRegenerate()
* @param array $extOpts
* @param bool $versioned
*/
$curTTL = null;
$v = $cache->get( $key, $curTTL, [ $cKey1, $cKey2 ] );
- if ( $versioned ) {
- $this->assertEquals( $value, $v[$cache::VFLD_DATA], "Value returned" );
- } else {
- $this->assertEquals( $value, $v, "Value returned" );
- }
+ $this->assertEquals( $value, $v, "Value returned" );
$this->assertLessThanOrEqual( 0, $curTTL, "Value has current TTL < 0 due to check keys" );
$wasSet = 0;
/**
* @dataProvider getWithSetCallback_provider
* @covers WANObjectCache::getWithSetCallback()
- * @covers WANObjectCache::doGetWithSetCallback()
+ * @covers WANObjectCache::fetchOrRegenerate()
* @param array $extOpts
* @param bool $versioned
*/
$this->assertEquals( 2, $wasSet, "Value re-calculated" );
}
- /**
- * @covers WANObjectCache::getWithSetCallback()
- * @covers WANObjectCache::doGetWithSetCallback()
- */
- public function testGetWithSetCallback_invalidCallback() {
- $this->setExpectedException( InvalidArgumentException::class );
- $this->cache->getWithSetCallback( 'key', 30, 'invalid callback' );
- }
-
/**
* @dataProvider getMultiWithSetCallback_provider
* @covers WANObjectCache::getMultiWithSetCallback
$value = "@efef$";
$keyedIds = new ArrayIterator( [ $keyB => 'efef' ] );
$v = $cache->getMultiWithSetCallback(
- $keyedIds, 30, $genFunc, [ 'lowTTL' => 0, 'lockTSE' => 5, ] + $extOpts );
+ $keyedIds, 30, $genFunc, [ 'lowTTL' => 0, 'lockTSE' => 5 ] + $extOpts );
$this->assertEquals( $value, $v[$keyB], "Value returned" );
$this->assertEquals( 1, $wasSet, "Value regenerated" );
- $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed yet in process cache" );
+ $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" );
+
$v = $cache->getMultiWithSetCallback(
- $keyedIds, 30, $genFunc, [ 'lowTTL' => 0, 'lockTSE' => 5, ] + $extOpts );
+ $keyedIds, 30, $genFunc, [ 'lowTTL' => 0, 'lockTSE' => 5 ] + $extOpts );
$this->assertEquals( $value, $v[$keyB], "Value returned" );
$this->assertEquals( 1, $wasSet, "Value not regenerated" );
- $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in process cache" );
+ $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" );
$mockWallClock += 1;
$curTTL = null;
$v = $cache->get( $keyC, $curTTL, [ $cKey1, $cKey2 ] );
- if ( $versioned ) {
- $this->assertEquals( $value, $v[$cache::VFLD_DATA], "Value returned" );
- } else {
- $this->assertEquals( $value, $v, "Value returned" );
- }
+ $this->assertEquals( $value, $v, "Value returned" );
$this->assertLessThanOrEqual( 0, $curTTL, "Value has current TTL < 0 due to check keys" );
$wasSet = 0;
$keyedIds, 30, $genFunc, [ 'lowTTL' => 0 ] + $extOpts );
$this->assertEquals( $value, $v[$keyB], "Value returned" );
$this->assertEquals( 1, $wasSet, "Value regenerated" );
- $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed yet in process cache" );
+ $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" );
+
$v = $cache->getMultiWithUnionSetCallback(
$keyedIds, 30, $genFunc, [ 'lowTTL' => 0 ] + $extOpts );
$this->assertEquals( $value, $v[$keyB], "Value returned" );
$this->assertEquals( 1, $wasSet, "Value not regenerated" );
- $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in process cache" );
+ $this->assertEquals( 0, $cache->getWarmupKeyMisses(), "Keys warmed in warmup cache" );
$mockWallClock += 1;
$curTTL = null;
$v = $cache->get( $keyC, $curTTL, [ $cKey1, $cKey2 ] );
- if ( $versioned ) {
- $this->assertEquals( $value, $v[$cache::VFLD_DATA], "Value returned" );
- } else {
- $this->assertEquals( $value, $v, "Value returned" );
- }
+ $this->assertEquals( $value, $v, "Value returned" );
$this->assertLessThanOrEqual( 0, $curTTL, "Value has current TTL < 0 due to check keys" );
$wasSet = 0;
/**
* @covers WANObjectCache::getWithSetCallback()
- * @covers WANObjectCache::doGetWithSetCallback()
+ * @covers WANObjectCache::fetchOrRegenerate()
*/
public function testLockTSE() {
$cache = $this->cache;
/**
* @covers WANObjectCache::getWithSetCallback()
- * @covers WANObjectCache::doGetWithSetCallback()
+ * @covers WANObjectCache::fetchOrRegenerate()
* @covers WANObjectCache::set()
*/
public function testLockTSESlow() {
/**
* @covers WANObjectCache::getWithSetCallback()
- * @covers WANObjectCache::doGetWithSetCallback()
+ * @covers WANObjectCache::fetchOrRegenerate()
*/
public function testBusyValue() {
$cache = $this->cache;
/**
* @dataProvider getWithSetCallback_versions_provider
* @covers WANObjectCache::getWithSetCallback()
- * @covers WANObjectCache::doGetWithSetCallback()
+ * @covers WANObjectCache::fetchOrRegenerate()
* @param array $extOpts
* @param bool $versioned
*/
$this->internalCache->set(
WANObjectCache::VALUE_KEY_PREFIX . $vKey1,
[
- WANObjectCache::FLD_VERSION => WANObjectCache::VERSION,
+ WANObjectCache::FLD_FORMAT_VERSION => WANObjectCache::VERSION,
WANObjectCache::FLD_VALUE => $value,
WANObjectCache::FLD_TTL => 3600,
WANObjectCache::FLD_TIME => $goodTime
$this->internalCache->set(
WANObjectCache::VALUE_KEY_PREFIX . $vKey2,
[
- WANObjectCache::FLD_VERSION => WANObjectCache::VERSION,
+ WANObjectCache::FLD_FORMAT_VERSION => WANObjectCache::VERSION,
WANObjectCache::FLD_VALUE => $value,
WANObjectCache::FLD_TTL => 3600,
WANObjectCache::FLD_TIME => $badTime
->setMethods( [ 'get', 'changeTTL' ] )->getMock();
$backend->expects( $this->once() )->method( 'get' )
->willReturn( [
- WANObjectCache::FLD_VERSION => WANObjectCache::VERSION,
+ WANObjectCache::FLD_FORMAT_VERSION => WANObjectCache::VERSION,
WANObjectCache::FLD_VALUE => 'value',
WANObjectCache::FLD_TTL => 3600,
WANObjectCache::FLD_TIME => 300,