3use Wikimedia\ScopedCallback;
17 if ( $this->
getCliArg(
'use-bagostuff' ) ) {
18 $name = $this->
getCliArg(
'use-bagostuff' );
20 $this->
cache = ObjectCache::newFromId( $name );
34 $cache = ObjectCache::newFromId(
'hash' );
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(
81 $callback =
function (
BagOStuff $cache, $key, $existingValue ) use ( &$usleep ) {
85 if ( $existingValue ===
false ) {
89 return $existingValue .
'merged';
93 $merged = $this->
cache->merge( $key, $callback, 0 );
94 $this->assertTrue( $merged );
95 $this->assertEquals(
'merged', $this->
cache->get( $key ) );
98 $merged = $this->
cache->merge( $key, $callback, 0 );
99 $this->assertTrue( $merged );
100 $this->assertEquals(
'mergedmerged', $this->
cache->get( $key ) );
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' ) );
170 $value = [
'this' =>
'is',
'a' =>
'test' ];
174 $this->assertEquals( $this->
cache->get( $key ),
$value );
186 return 'hello kitty';
190 $this->assertEquals(
'hello kitty',
$value );
191 $this->assertEquals(
$value, $this->
cache->get( $key ) );
199 $this->
cache->add( $key, 0 );
200 $this->
cache->incr( $key );
202 $actualValue = $this->
cache->get( $key );
203 $this->assertEquals( $expectedValue, $actualValue,
'Value should be 1 after incrementing' );
211 $val = $this->
cache->incrWithInit( $key, 0, 1, 3 );
212 $this->assertEquals( 3, $val,
"Correct init value" );
214 $val = $this->
cache->incrWithInit( $key, 0, 1, 3 );
215 $this->assertEquals( 4, $val,
"Correct init value" );
222 $value1 = [
'this' =>
'is',
'a' =>
'test' ];
223 $value2 = [
'this' =>
'is',
'another' =>
'test' ];
224 $value3 = [
'testing a key that may be encoded when sent to cache backend' ];
225 $value4 = [
'another test where chars in key will be encoded' ];
232 'flowdb:flow_ref:wiki:by-source:v3:Parser\'s_"broken"_+_(page)_&_grill:testwiki:1:4.7'
235 $this->
cache->add( $key1, $value1 );
236 $this->
cache->add( $key2, $value2 );
237 $this->
cache->add( $key3, $value3 );
238 $this->
cache->add( $key4, $value4 );
241 [ $key1 => $value1, $key2 => $value2, $key3 => $value3, $key4 => $value4 ],
242 $this->
cache->getMulti( [ $key1, $key2, $key3, $key4 ] )
246 $this->
cache->delete( $key1 );
247 $this->
cache->delete( $key2 );
248 $this->
cache->delete( $key3 );
249 $this->
cache->delete( $key4 );
257 $value1 = $this->
cache->getScopedLock( $key, 0 );
258 $value2 = $this->
cache->getScopedLock( $key, 0 );
260 $this->
assertType( ScopedCallback::class, $value1,
'First call returned lock' );
261 $this->assertNull( $value2,
'Duplicate call returned no lock' );
265 $value3 = $this->
cache->getScopedLock( $key, 0 );
266 $this->
assertType( ScopedCallback::class, $value3,
'Lock returned callback after release' );
269 $value1 = $this->
cache->getScopedLock( $key, 0, 5,
'reentry' );
270 $value2 = $this->
cache->getScopedLock( $key, 0, 5,
'reentry' );
272 $this->
assertType( ScopedCallback::class, $value1,
'First reentrant call returned lock' );
273 $this->
assertType( ScopedCallback::class, $value1,
'Second reentrant call returned lock' );
281 $logger = $this->createMock( Psr\Log\NullLogger::class );
282 $logger->expects( $this->once() )
283 ->method(
'warning' )
284 ->with(
'Duplicate get(): "{key}" fetched {count} times', [
290 'reportDupes' =>
true,
291 'asyncHandler' =>
'DeferredUpdates::addCallableUpdate',
298 DeferredUpdates::doUpdates();
wfMemcKey()
Make a cache key for the local wiki.
testChangeTTL()
BagOStuff::changeTTL.
testGetWithSetCallback()
BagOStuff::getWithSetCallback.
testGetScopedLock()
BagOStuff::getScopedLock.
testIncrWithInit()
BagOStuff::incrWithInit.
testReportDupes()
BagOStuff::__construct BagOStuff::trackDuplicateKeys.
testGetMulti()
BagOStuff::getMulti.
testMakeKey()
BagOStuff::makeGlobalKey BagOStuff::makeKeyInternal.
testIncr()
BagOStuff::incr.
testMerge()
BagOStuff::merge BagOStuff::mergeViaLock.
interface is intended to be more or less compatible with the PHP memcached client.
makeKey( $class, $component=null)
Make a cache key, scoped to this instance's keyspace.
get( $key, $flags=0, $oldFlags=null)
Get an item with the given key.
makeKeyInternal( $keyspace, $args)
Construct a cache key.
makeGlobalKey( $class, $component=null)
Make a global cache key.
A BagOStuff object with no objects in it.
Simple store for keeping values in an associative array for the current process.
A cache class that replicates all writes to multiple child caches.
you have access to all of the normal MediaWiki so you can get a DB use the cache