3 use Wikimedia\ScopedCallback;
17 if ( $this->
getCliArg(
'use-bagostuff' ) ) {
39 $this->assertStringMatchesFormat(
40 '%Sfirst%Ssecond%Sthird%S',
42 'Local key interpolates parameters'
45 $this->assertStringMatchesFormat(
46 'global%Sfirst%Ssecond%Sthird%S',
48 'Global key interpolates parameters and contains global prefix'
51 $this->assertNotEquals(
54 'Local key and global key with same parameters should not be equal'
57 $this->assertNotEquals(
85 if ( $existingValue ===
false ) {
89 return $existingValue .
'merged';
93 $merged = $this->
cache->merge( $key, $callback, 0 );
94 $this->assertTrue( $merged );
95 $this->assertEquals( $this->
cache->get( $key ),
'merged' );
98 $merged = $this->
cache->merge( $key, $callback, 0 );
99 $this->assertTrue( $merged );
100 $this->assertEquals( $this->
cache->get( $key ),
'mergedmerged' );
108 $fork = (bool)$this->
getCliArg(
'use-bagostuff' );
109 $fork &= function_exists(
'pcntl_fork' );
123 $merged = $this->
cache->merge( $key, $callback, 0, 1 );
126 $this->assertFalse( $merged );
130 $this->assertEquals( $this->
cache->get( $key ),
'mergedmergedmerged' );
132 $this->
cache->merge( $key, $callback, 0, 1 );
152 $this->assertTrue( $this->
cache->changeTTL( $key, 5 ) );
153 $this->assertEquals( $this->
cache->get( $key ),
$value );
154 $this->
cache->delete( $key );
155 $this->assertFalse( $this->
cache->changeTTL( $key, 5 ) );
163 $this->assertTrue( $this->
cache->add( $key,
'test' ) );
167 $value = [
'this' =>
'is',
'a' =>
'test' ];
171 $this->assertEquals( $this->
cache->get( $key ),
$value );
183 return 'hello kitty';
187 $this->assertEquals(
'hello kitty',
$value );
188 $this->assertEquals(
$value, $this->
cache->get( $key ) );
196 $this->
cache->add( $key, 0 );
197 $this->
cache->incr( $key );
199 $actualValue = $this->
cache->get( $key );
200 $this->assertEquals( $expectedValue, $actualValue,
'Value should be 1 after incrementing' );
208 $val = $this->
cache->incrWithInit( $key, 0, 1, 3 );
209 $this->assertEquals( 3, $val,
"Correct init value" );
211 $val = $this->
cache->incrWithInit( $key, 0, 1, 3 );
212 $this->assertEquals( 4, $val,
"Correct init value" );
219 $value1 = [
'this' =>
'is',
'a' =>
'test' ];
220 $value2 = [
'this' =>
'is',
'another' =>
'test' ];
221 $value3 = [
'testing a key that may be encoded when sent to cache backend' ];
222 $value4 = [
'another test where chars in key will be encoded' ];
229 'flowdb:flow_ref:wiki:by-source:v3:Parser\'s_"broken"_+_(page)_&_grill:testwiki:1:4.7'
232 $this->
cache->add( $key1, $value1 );
233 $this->
cache->add( $key2, $value2 );
234 $this->
cache->add( $key3, $value3 );
235 $this->
cache->add( $key4, $value4 );
238 [ $key1 => $value1, $key2 => $value2, $key3 => $value3, $key4 => $value4 ],
239 $this->
cache->getMulti( [ $key1, $key2, $key3, $key4 ] )
243 $this->
cache->delete( $key1 );
244 $this->
cache->delete( $key2 );
245 $this->
cache->delete( $key3 );
246 $this->
cache->delete( $key4 );
254 $value1 = $this->
cache->getScopedLock( $key, 0 );
255 $value2 = $this->
cache->getScopedLock( $key, 0 );
258 $this->assertNull( $value2,
'Duplicate call returned no lock' );
262 $value3 = $this->
cache->getScopedLock( $key, 0 );
266 $value1 = $this->
cache->getScopedLock( $key, 0, 5,
'reentry' );
267 $value2 = $this->
cache->getScopedLock( $key, 0, 5,
'reentry' );
279 $logger->expects( $this->once() )
280 ->method(
'warning' )
281 ->with(
'Duplicate get(): "{key}" fetched {count} times', [
287 'reportDupes' =>
true,
288 'asyncHandler' =>
'DeferredUpdates::addCallableUpdate',