19 if ( $this->
getCliArg(
'use-bagostuff' ) !==
null ) {
20 $name = $this->
getCliArg(
'use-bagostuff' );
22 $this->
cache = ObjectCache::newFromId( $name );
28 $this->
cache->delete( $this->
cache->makeKey( self::TEST_KEY ) );
29 $this->
cache->delete( $this->
cache->makeKey( self::TEST_KEY ) .
':lock' );
37 $cache = ObjectCache::newFromId(
'hash' );
43 '%Sfirst%Ssecond%Sthird%S',
45 'Local key interpolates parameters'
49 'global%Sfirst%Ssecond%Sthird%S',
51 'Global key interpolates parameters and contains global prefix'
57 'Local key and global key with same parameters should not be equal'
71 $key = $this->
cache->makeKey( self::TEST_KEY );
82 return ( $oldVal ===
false ) ?
'merged' : $oldVal .
'merged';
86 $merged = $this->
cache->merge( $key, $callback, 5 );
91 $merged = $this->
cache->merge( $key, $callback, 5 );
98 $this->
cache->merge( $key, $callback, 5, 1 ),
99 'Non-blocking merge (CAS)'
102 $wrapper = \Wikimedia\TestingAccessWrapper::newFromObject( $this->
cache );
103 $n = count( $wrapper->caches );
114 $key = $this->
cache->makeKey( self::TEST_KEY );
120 $this->
cache->delete( $key );
128 $key = $this->
cache->makeKey( self::TEST_KEY );
136 $value = [
'this' =>
'is',
'a' =>
'test' ];
138 $key = $this->
cache->makeKey( self::TEST_KEY );
149 $key = $this->
cache->makeKey( self::TEST_KEY );
154 return 'hello kitty';
166 $key = $this->
cache->makeKey( self::TEST_KEY );
167 $this->
cache->add( $key, 0, 5 );
168 $this->
cache->incr( $key );
170 $actualValue = $this->
cache->get( $key );
171 $this->
assertEquals( $expectedValue, $actualValue,
'Value should be 1 after incrementing' );
178 $key = $this->
cache->makeKey( self::TEST_KEY );
179 $val = $this->
cache->incrWithInit( $key, 0, 1, 3 );
182 $val = $this->
cache->incrWithInit( $key, 0, 1, 3 );
190 $value1 = [
'this' =>
'is',
'a' =>
'test' ];
191 $value2 = [
'this' =>
'is',
'another' =>
'test' ];
192 $value3 = [
'testing a key that may be encoded when sent to cache backend' ];
193 $value4 = [
'another test where chars in key will be encoded' ];
195 $key1 = $this->
cache->makeKey(
'test-1' );
196 $key2 = $this->
cache->makeKey(
'test-2' );
198 $key3 = $this->
cache->makeKey(
'will-%-encode' );
199 $key4 = $this->
cache->makeKey(
200 'flowdb:flow_ref:wiki:by-source:v3:Parser\'s_"broken"_+_(page)_&_grill:testwiki:1:4.7'
204 $this->
cache->delete( $key1 );
205 $this->
cache->delete( $key2 );
206 $this->
cache->delete( $key3 );
207 $this->
cache->delete( $key4 );
209 $this->
cache->add( $key1, $value1, 5 );
210 $this->
cache->add( $key2, $value2, 5 );
211 $this->
cache->add( $key3, $value3, 5 );
212 $this->
cache->add( $key4, $value4, 5 );
215 [ $key1 => $value1, $key2 => $value2, $key3 => $value3, $key4 => $value4 ],
216 $this->
cache->getMulti( [ $key1, $key2, $key3, $key4 ] )
220 $this->
cache->delete( $key1 );
221 $this->
cache->delete( $key2 );
222 $this->
cache->delete( $key3 );
223 $this->
cache->delete( $key4 );
232 $this->
cache->makeKey(
'test-1' ) =>
'Siberian',
233 $this->
cache->makeKey(
'test-2' ) => [
'Huskies' ],
234 $this->
cache->makeKey(
'test-3' ) => [
'are' =>
'the' ],
235 $this->
cache->makeKey(
'test-4' ) => (
object)[
'greatest' =>
'animal' ],
236 $this->
cache->makeKey(
'test-5' ) => 4,
237 $this->
cache->makeKey(
'test-6' ) =>
'ever'
240 $this->
cache->setMulti( $map, 5 );
243 $this->
cache->getMulti( array_keys( $map ) )
246 $this->
assertTrue( $this->
cache->deleteMulti( array_keys( $map ), 5 ) );
250 $this->
cache->getMulti( array_keys( $map ) )
258 $key = $this->
cache->makeKey( self::TEST_KEY );
259 $value1 = $this->
cache->getScopedLock( $key, 0 );
260 $value2 = $this->
cache->getScopedLock( $key, 0 );
262 $this->
assertType( ScopedCallback::class, $value1,
'First call returned lock' );
263 $this->
assertNull( $value2,
'Duplicate call returned no lock' );
267 $value3 = $this->
cache->getScopedLock( $key, 0 );
268 $this->
assertType( ScopedCallback::class, $value3,
'Lock returned callback after release' );
271 $value1 = $this->
cache->getScopedLock( $key, 0, 5,
'reentry' );
272 $value2 = $this->
cache->getScopedLock( $key, 0, 5,
'reentry' );
274 $this->
assertType( ScopedCallback::class, $value1,
'First reentrant call returned lock' );
275 $this->
assertType( ScopedCallback::class, $value1,
'Second reentrant call returned lock' );
283 $logger = $this->
createMock( Psr\Log\NullLogger::class );
284 $logger->expects( $this->
once() )
285 ->method(
'warning' )
286 ->with(
'Duplicate get(): "{key}" fetched {count} times', [
292 'reportDupes' =>
true,
293 'asyncHandler' =>
'DeferredUpdates::addCallableUpdate',
300 DeferredUpdates::doUpdates();
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
testSetDeleteMulti()
BagOStuff::setMulti BagOStuff::deleteMulti.
testChangeTTL()
BagOStuff::changeTTL.
testGetWithSetCallback()
BagOStuff::get BagOStuff::set BagOStuff::getWithSetCallback.
testLocking()
BagOStuff::lock() BagOStuff::unlock()
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::mergeViaCas.
Class representing a cache/ephemeral data store.
get( $key, $flags=0)
Get an item with the given key.
makeKey( $class, $component=null)
Make a cache key, scoped to this instance's keyspace.
set( $key, $value, $exptime=0, $flags=0)
Set an item.
makeKeyInternal( $keyspace, $args)
Construct a cache key.
makeGlobalKey( $class, $component=null)
Make a global cache key.
Simple store for keeping values in an associative array for the current process.
A cache class that replicates all writes to multiple child caches.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
you have access to all of the normal MediaWiki so you can get a DB use the cache