public function testSetOver() {
$key = wfRandomString();
- for ( $i=0; $i<3; ++$i ) {
+ for ( $i = 0; $i < 3; ++$i ) {
$value = wfRandomString();
- $this->cache->set($key, $value, 3);
+ $this->cache->set( $key, $value, 3 );
$this->assertEquals( $this->cache->get( $key ), $value );
}
$cKey2 = wfRandomString();
$wasSet = 0;
- $func = function() use ( &$wasSet, $value ) { ++$wasSet; return $value; };
+ $func = function( $old, &$ttl ) use ( &$wasSet, $value ) {
+ ++$wasSet;
+ $ttl = 20; // override with another value
+ return $value;
+ };
$wasSet = 0;
$v = $cache->getWithSetCallback( $key, $func, 30, array(), array( 'lockTSE' => 5 ) );
$this->assertEquals( $v, $value );
$this->assertEquals( 1, $wasSet, "Value regenerated" );
+ $curTTL = null;
+ $v = $cache->get( $key, $curTTL );
+ $this->assertLessThanOrEqual( 20, $curTTL, 'Current TTL between 19-20 (overriden)' );
+ $this->assertGreaterThanOrEqual( 19, $curTTL, 'Current TTL between 19-20 (overriden)' );
+
$wasSet = 0;
$v = $cache->getWithSetCallback( $key, $func, 30, array(), array( 'lockTSE' => 5 ) );
$this->assertEquals( $v, $value );
public function testTouchKeys() {
$key = wfRandomString();
+ $priorTime = microtime( true );
+ usleep( 1 );
$t0 = $this->cache->getCheckKeyTime( $key );
- $this->assertFalse( $t0, 'Check key time is false' );
+ $this->assertGreaterThanOrEqual( $priorTime, $t0, 'Check key auto-created' );
$priorTime = microtime( true );
usleep( 1 );
$t4 = $this->cache->getCheckKeyTime( $key );
$this->assertEquals( $t3, $t4, 'Check key time did not change' );
}
-}
\ No newline at end of file
+}