9 protected function setUp() {
14 'pool' =>
'testcache-hash',
20 $this->internalCache = $wanCache->cache;
36 $this->
cache->get( $key, $curTTL, [], $asOf );
37 $this->assertNull( $curTTL,
"Current TTL is null" );
38 $this->assertNull( $asOf,
"Current as-of-time is infinite" );
40 $t = microtime(
true );
43 $this->assertEquals(
$value, $this->
cache->get( $key, $curTTL, [], $asOf ) );
44 if ( is_infinite( $ttl ) || $ttl == 0 ) {
45 $this->assertTrue( is_infinite( $curTTL ),
"Current TTL is infinite" );
47 $this->assertGreaterThan( 0, $curTTL,
"Current TTL > 0" );
48 $this->assertLessThanOrEqual( $ttl, $curTTL,
"Current TTL < nominal TTL" );
50 $this->assertGreaterThanOrEqual(
$t - 1, $asOf,
"As-of-time in range of set() time" );
51 $this->assertLessThanOrEqual(
$t + 1, $asOf,
"As-of-time in range of set() time" );
77 $this->assertFalse(
$value,
"Non-existing key has false value" );
78 $this->assertNull( $curTTL,
"Non-existing key has null current TTL" );
86 for ( $i = 0; $i < 3; ++$i ) {
90 $this->assertEquals( $this->
cache->get( $key ),
$value );
100 $this->
cache->set( $key,
$value, 3, [
'since' => microtime(
true ) - 30 ] );
102 $this->assertFalse( $this->
cache->get( $key ),
"Stale set() value ignored" );
107 $callback =
function ()
use ( &$hit ) {
112 $groups = [
'thiscache:1',
'thatcache:1',
'somecache:1' ];
114 foreach (
$keys as $i => $key ) {
115 $this->
cache->getWithSetCallback(
116 $key, 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
118 $this->assertEquals( 3, $hit );
120 foreach (
$keys as $i => $key ) {
121 $this->
cache->getWithSetCallback(
122 $key, 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
124 $this->assertEquals( 3, $hit,
"Values cached" );
126 foreach (
$keys as $i => $key ) {
127 $this->
cache->getWithSetCallback(
128 "$key-2", 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
130 $this->assertEquals( 6, $hit );
132 foreach (
$keys as $i => $key ) {
133 $this->
cache->getWithSetCallback(
134 "$key-2", 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
136 $this->assertEquals( 6, $hit,
"New values cached" );
138 foreach (
$keys as $i => $key ) {
139 $this->
cache->delete( $key );
140 $this->
cache->getWithSetCallback(
141 $key, 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
143 $this->assertEquals( 9, $hit,
"Values evicted" );
145 $key = reset(
$keys );
147 $this->
cache->getWithSetCallback( $key, 100, $callback, [
'pcTTL' => 5 ] );
148 $this->
cache->getWithSetCallback( $key, 100, $callback, [
'pcTTL' => 5 ] );
149 $this->assertEquals( 10, $hit,
"Value cached" );
150 $outerCallback =
function ()
use ( &$callback, $key ) {
151 $v = $this->
cache->getWithSetCallback( $key, 100, $callback, [
'pcTTL' => 5 ] );
155 $this->
cache->getWithSetCallback( $key, 100, $outerCallback );
156 $this->assertEquals( 11, $hit,
"Nested callback value process cache skipped" );
177 $func =
function( $old, &$ttl, &$opts, $asOf )
178 use ( &$wasSet, &$priorValue, &$priorAsOf,
$value )
189 $this->assertEquals(
$value, $v,
"Value returned" );
190 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
191 $this->assertFalse( $priorValue,
"No prior value" );
192 $this->assertNull( $priorAsOf,
"No prior value" );
196 $this->assertLessThanOrEqual( 20, $curTTL,
'Current TTL between 19-20 (overriden)' );
197 $this->assertGreaterThanOrEqual( 19, $curTTL,
'Current TTL between 19-20 (overriden)' );
204 $this->assertEquals(
$value, $v,
"Value returned" );
205 $this->assertEquals( 0, $wasSet,
"Value not regenerated" );
207 $priorTime = microtime(
true );
211 $key, 30, $func, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
213 $this->assertEquals(
$value, $v,
"Value returned" );
214 $this->assertEquals( 1, $wasSet,
"Value regenerated due to check keys" );
215 $this->assertEquals(
$value, $priorValue,
"Has prior value" );
216 $this->assertInternalType(
'float', $priorAsOf,
"Has prior value" );
218 $this->assertGreaterThanOrEqual( $priorTime, $t1,
'Check keys generated on miss' );
220 $this->assertGreaterThanOrEqual( $priorTime, $t2,
'Check keys generated on miss' );
222 $priorTime = microtime(
true );
225 $key, 30, $func, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
227 $this->assertEquals(
$value, $v,
"Value returned" );
228 $this->assertEquals( 1, $wasSet,
"Value regenerated due to still-recent check keys" );
230 $this->assertLessThanOrEqual( $priorTime, $t1,
'Check keys did not change again' );
232 $this->assertLessThanOrEqual( $priorTime, $t2,
'Check keys did not change again' );
235 $v =
$cache->
get( $key, $curTTL, [ $cKey1, $cKey2 ] );
237 $this->assertEquals(
$value, $v[$cache::VFLD_DATA],
"Value returned" );
239 $this->assertEquals(
$value, $v,
"Value returned" );
241 $this->assertLessThanOrEqual( 0, $curTTL,
"Value has current TTL < 0 due to check keys" );
246 $this->assertEquals(
$value, $v,
"Value returned" );
249 $this->assertEquals(
$value, $v,
"Value still returned after deleted" );
250 $this->assertEquals( 1, $wasSet,
"Value process cached while deleted" );
256 [ [
'version' => 1 ],
true ]
279 $genFunc =
function ( $id, $old, &$ttl, &$opts, $asOf )
use (
280 &$wasSet, &$priorValue, &$priorAsOf
290 $keyedIds =
new ArrayIterator( [ $keyA => 3353 ] );
293 $keyedIds, 30, $genFunc, [
'lockTSE' => 5 ] + $extOpts );
294 $this->assertEquals(
$value, $v[$keyA],
"Value returned" );
295 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
296 $this->assertFalse( $priorValue,
"No prior value" );
297 $this->assertNull( $priorAsOf,
"No prior value" );
301 $this->assertLessThanOrEqual( 20, $curTTL,
'Current TTL between 19-20 (overriden)' );
302 $this->assertGreaterThanOrEqual( 19, $curTTL,
'Current TTL between 19-20 (overriden)' );
306 $keyedIds =
new ArrayIterator( [ $keyB =>
'efef' ] );
308 $keyedIds, 30, $genFunc, [
'lowTTL' => 0,
'lockTSE' => 5, ] + $extOpts );
309 $this->assertEquals(
$value, $v[$keyB],
"Value returned" );
310 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
312 $keyedIds, 30, $genFunc, [
'lowTTL' => 0,
'lockTSE' => 5, ] + $extOpts );
313 $this->assertEquals(
$value, $v[$keyB],
"Value returned" );
314 $this->assertEquals( 1, $wasSet,
"Value not regenerated" );
316 $priorTime = microtime(
true );
319 $keyedIds =
new ArrayIterator( [ $keyB =>
'efef' ] );
321 $keyedIds, 30, $genFunc, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
323 $this->assertEquals(
$value, $v[$keyB],
"Value returned" );
324 $this->assertEquals( 1, $wasSet,
"Value regenerated due to check keys" );
325 $this->assertEquals(
$value, $priorValue,
"Has prior value" );
326 $this->assertInternalType(
'float', $priorAsOf,
"Has prior value" );
328 $this->assertGreaterThanOrEqual( $priorTime, $t1,
'Check keys generated on miss' );
330 $this->assertGreaterThanOrEqual( $priorTime, $t2,
'Check keys generated on miss' );
332 $priorTime = microtime(
true );
335 $keyedIds =
new ArrayIterator( [ $keyC => 43636 ] );
337 $keyedIds, 30, $genFunc, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
339 $this->assertEquals(
$value, $v[$keyC],
"Value returned" );
340 $this->assertEquals( 1, $wasSet,
"Value regenerated due to still-recent check keys" );
342 $this->assertLessThanOrEqual( $priorTime, $t1,
'Check keys did not change again' );
344 $this->assertLessThanOrEqual( $priorTime, $t2,
'Check keys did not change again' );
347 $v =
$cache->
get( $keyC, $curTTL, [ $cKey1, $cKey2 ] );
349 $this->assertEquals(
$value, $v[$cache::VFLD_DATA],
"Value returned" );
351 $this->assertEquals(
$value, $v,
"Value returned" );
353 $this->assertLessThanOrEqual( 0, $curTTL,
"Value has current TTL < 0 due to check keys" );
357 $keyedIds =
new ArrayIterator( [ $key => 242424 ] );
359 $keyedIds, 30, $genFunc, [
'pcTTL' => 5 ] + $extOpts );
360 $this->assertEquals(
"@{$keyedIds[$key]}$", $v[$key],
"Value returned" );
362 $keyedIds =
new ArrayIterator( [ $key => 242424 ] );
364 $keyedIds, 30, $genFunc, [
'pcTTL' => 5 ] + $extOpts );
365 $this->assertEquals(
"@{$keyedIds[$key]}$", $v[$key],
"Value still returned after deleted" );
366 $this->assertEquals( 1, $wasSet,
"Value process cached while deleted" );
369 $ids = [ 1, 2, 3, 4, 5, 6 ];
371 return $wanCache->makeKey(
'test', $id );
374 $genFunc =
function ( $id, $oldValue, &$ttl,
array &$setops )
use ( &$calls ) {
382 [
"val-1",
"val-2",
"val-3",
"val-4",
"val-5",
"val-6" ],
383 array_values( $values ),
384 "Correct values in correct order"
387 array_map( $keyFunc, $ids, array_fill( 0, count( $ids ), $this->
cache ) ),
388 array_keys( $values ),
389 "Correct keys in correct order"
391 $this->assertEquals( count( $ids ), $calls );
394 $this->assertEquals( count( $ids ), $calls,
"Values cached" );
400 [ [
'version' => 1 ],
true ]
423 $this->assertEquals( 1, $calls,
'Value was populated' );
426 $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
430 [
'lockTSE' => 5,
'checkKeys' => $checkKeys ] );
431 $this->assertEquals(
$value,
$ret,
'Old value used' );
432 $this->assertEquals( 1, $calls,
'Callback was not used' );
436 [
'lockTSE' => 5,
'checkKeys' => $checkKeys ] );
437 $this->assertEquals(
$value,
$ret,
'Callback was used; interim saved' );
438 $this->assertEquals( 2, $calls,
'Callback was used; interim saved' );
441 [
'lockTSE' => 5,
'checkKeys' => $checkKeys ] );
442 $this->assertEquals(
$value,
$ret,
'Callback was not used; used interim' );
443 $this->assertEquals( 2, $calls,
'Callback was not used; used interim' );
456 $func =
function( $oldValue, &$ttl, &$setOpts )
use ( &$calls,
$value,
$cache, $key ) {
458 $setOpts[
'since'] = microtime(
true ) - 10;
468 $this->assertEquals(
$value,
$cache->
get( $key, $curTTL ),
'Value was populated' );
469 $this->assertLessThan( 0, $curTTL,
'Value has negative curTTL' );
470 $this->assertEquals( 1, $calls,
'Value was generated' );
473 $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
476 $this->assertEquals( 1, $calls,
'Callback was not used' );
499 $this->assertEquals( 1, $calls,
'Value was populated' );
502 $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
506 [
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
507 $this->assertEquals(
$value,
$ret,
'Callback used' );
508 $this->assertEquals( 2, $calls,
'Callback used' );
511 [
'lockTSE' => 30,
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
512 $this->assertEquals(
$value,
$ret,
'Old value used' );
513 $this->assertEquals( 2, $calls,
'Callback was not used' );
517 [
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
518 $this->assertEquals( $busyValue,
$ret,
'Callback was not used; used busy value' );
519 $this->assertEquals( 2, $calls,
'Callback was not used; used busy value' );
521 $this->internalCache->delete( $cache::MUTEX_KEY_PREFIX . $key );
523 [
'lockTSE' => 30,
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
524 $this->assertEquals(
$value,
$ret,
'Callback was used; saved interim' );
525 $this->assertEquals( 3, $calls,
'Callback was used; saved interim' );
527 $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
529 [
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
530 $this->assertEquals(
$value,
$ret,
'Callback was not used; used interim' );
531 $this->assertEquals( 3, $calls,
'Callback was not used; used interim' );
540 $value1 = [
'this' =>
'is',
'a' =>
'test' ];
541 $value2 = [
'this' =>
'is',
'another' =>
'test' ];
552 [ $key1 => $value1, $key2 => $value2 ],
554 'Result array populated'
557 $this->assertEquals( 2, count( $curTTLs ),
"Two current TTLs in array" );
558 $this->assertGreaterThan( 0, $curTTLs[$key1],
"Key 1 has current TTL > 0" );
559 $this->assertGreaterThan( 0, $curTTLs[$key2],
"Key 2 has current TTL > 0" );
564 $priorTime = microtime(
true );
568 [ $key1 => $value1, $key2 => $value2 ],
569 $cache->
getMulti( [ $key1, $key2, $key3 ], $curTTLs, [ $cKey1, $cKey2 ] ),
570 "Result array populated even with new check keys"
573 $this->assertGreaterThanOrEqual( $priorTime, $t1,
'Check key 1 generated on miss' );
575 $this->assertGreaterThanOrEqual( $priorTime, $t2,
'Check key 2 generated on miss' );
576 $this->assertEquals( 2, count( $curTTLs ),
"Current TTLs array set" );
577 $this->assertLessThanOrEqual( 0, $curTTLs[$key1],
'Key 1 has current TTL <= 0' );
578 $this->assertLessThanOrEqual( 0, $curTTLs[$key2],
'Key 2 has current TTL <= 0' );
583 [ $key1 => $value1, $key2 => $value2 ],
584 $cache->
getMulti( [ $key1, $key2, $key3 ], $curTTLs, [ $cKey1, $cKey2 ] ),
585 "Result array still populated even with new check keys"
587 $this->assertEquals( 2, count( $curTTLs ),
"Current TTLs still array set" );
588 $this->assertLessThan( 0, $curTTLs[$key1],
'Key 1 has negative current TTL' );
589 $this->assertLessThan( 0, $curTTLs[$key2],
'Key 2 has negative current TTL' );
608 foreach ( [ $checkAll, $check1, $check2 ]
as $checkKey ) {
624 [
'key1' => $value1,
'key2' => $value2 ],
628 $this->assertGreaterThanOrEqual( 9.5, $curTTLs[
'key1'],
'Initial ttls' );
629 $this->assertLessThanOrEqual( 10.5, $curTTLs[
'key1'],
'Initial ttls' );
630 $this->assertGreaterThanOrEqual( 9.5, $curTTLs[
'key2'],
'Initial ttls' );
631 $this->assertLessThanOrEqual( 10.5, $curTTLs[
'key2'],
'Initial ttls' );
643 [
'key1' => $value1,
'key2' => $value2 ],
645 'key1 expired by check1, but value still provided'
647 $this->assertLessThan( 0, $curTTLs[
'key1'],
'key1 TTL expired' );
648 $this->assertGreaterThan( 0, $curTTLs[
'key2'],
'key2 still valid' );
660 [
'key1' => $value1,
'key2' => $value2 ],
662 'All keys expired by checkAll, but value still provided'
664 $this->assertLessThan( 0, $curTTLs[
'key1'],
'key1 expired by checkAll' );
665 $this->assertLessThan( 0, $curTTLs[
'key2'],
'key2 expired by checkAll' );
675 for ( $i = 0; $i < 500; ++$i ) {
679 $cache->
get( $key, $curTTL, [ $checkKey ] );
682 $v =
$cache->
get( $key, $curTTL, [ $checkKey ] );
684 $this->assertEquals(
'val', $v );
685 $this->assertLessThan( 0, $curTTL,
"Step $i: CTL < 0 (miss/set/hit)" );
688 for ( $i = 0; $i < 500; ++$i ) {
694 $v =
$cache->
get( $key, $curTTL, [ $checkKey ] );
696 $this->assertEquals(
'val', $v );
697 $this->assertLessThan( 0, $curTTL,
"Step $i: CTL < 0 (set/hit)" );
710 $v = $this->
cache->get( $key, $curTTL );
711 $this->assertEquals(
$value, $v,
"Key was created with value" );
712 $this->assertGreaterThan( 0, $curTTL,
"Existing key has current TTL > 0" );
714 $this->
cache->delete( $key );
717 $v = $this->
cache->get( $key, $curTTL );
718 $this->assertFalse( $v,
"Deleted key has false value" );
719 $this->assertLessThan( 0, $curTTL,
"Deleted key has current TTL < 0" );
722 $v = $this->
cache->get( $key, $curTTL );
723 $this->assertFalse( $v,
"Deleted key is tombstoned and has false value" );
724 $this->assertLessThan( 0, $curTTL,
"Deleted key is tombstoned and has current TTL < 0" );
730 $v = $this->
cache->get( $key, $curTTL );
731 $this->assertFalse( $v,
"Deleted key has false value" );
732 $this->assertNull( $curTTL,
"Deleted key has null current TTL" );
735 $v = $this->
cache->get( $key, $curTTL );
736 $this->assertEquals(
$value, $v,
"Key was created with value" );
737 $this->assertGreaterThan( 0, $curTTL,
"Existing key has current TTL > 0" );
752 $func =
function( $old, &$ttl )
use ( &$wasSet,
$value ) {
760 $this->assertEquals(
$value, $v,
"Value returned" );
761 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
763 $this->assertEquals( 1, $wasSet,
"Value not regenerated" );
766 $verOpts = [
'version' => $extOpts[
'version'] + 1 ];
770 $this->assertEquals(
$value, $v,
"Value returned" );
771 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
775 $this->assertEquals(
$value, $v,
"Value returned" );
776 $this->assertEquals( 0, $wasSet,
"Value not regenerated" );
781 $this->assertEquals( 0, $wasSet,
"Value not regenerated" );
786 $this->assertEquals(
$value, $v,
"Value returned" );
787 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
791 $verOpts = [
'version' => $extOpts[
'version'] + 1 ];
793 $this->assertEquals(
$value, $v,
"Value returned" );
794 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
801 [ [
'version' => 1 ],
true ]
813 $priorTime = microtime(
true );
815 $t0 = $this->
cache->getCheckKeyTime( $key );
816 $this->assertGreaterThanOrEqual( $priorTime, $t0,
'Check key auto-created' );
818 $priorTime = microtime(
true );
820 $this->
cache->touchCheckKey( $key );
821 $t1 = $this->
cache->getCheckKeyTime( $key );
822 $this->assertGreaterThanOrEqual( $priorTime, $t1,
'Check key created' );
824 $t2 = $this->
cache->getCheckKeyTime( $key );
825 $this->assertEquals( $t1, $t2,
'Check key time did not change' );
828 $this->
cache->touchCheckKey( $key );
829 $t3 = $this->
cache->getCheckKeyTime( $key );
830 $this->assertGreaterThan( $t2, $t3,
'Check key time increased' );
832 $t4 = $this->
cache->getCheckKeyTime( $key );
833 $this->assertEquals( $t3, $t4,
'Check key time did not change' );
836 $this->
cache->resetCheckKey( $key );
837 $t5 = $this->
cache->getCheckKeyTime( $key );
838 $this->assertGreaterThan( $t4, $t5,
'Check key time increased' );
840 $t6 = $this->
cache->getCheckKeyTime( $key );
841 $this->assertEquals( $t5, $t6,
'Check key time did not change' );
854 $this->internalCache->set(
858 $this->internalCache->set(
862 $this->internalCache->set(
869 $v = $this->
cache->get( $key, $curTTL, [ $tKey1, $tKey2 ] );
870 $this->assertEquals(
$value, $v,
"Value matches" );
871 $this->assertLessThan( -4.9, $curTTL,
"Correct CTL" );
872 $this->assertGreaterThan( -5.1, $curTTL,
"Correct CTL" );
882 $opts = [
'lag' => 300,
'since' => microtime(
true ) ];
884 $this->assertEquals(
$value, $this->
cache->get( $key ),
"Rep-lagged value written." );
887 $opts = [
'lag' => 0,
'since' => microtime(
true ) - 300 ];
889 $this->assertEquals(
false, $this->
cache->get( $key ),
"Trx-lagged value not written." );
892 $opts = [
'lag' => 5,
'since' => microtime(
true ) - 5 ];
894 $this->assertEquals(
false, $this->
cache->get( $key ),
"Lagged value not written." );
904 $opts = [
'pending' =>
true ];
906 $this->assertEquals(
false, $this->
cache->get( $key ),
"Pending value not written." );
910 $localBag = $this->getMock(
'EmptyBagOStuff', [
'set',
'delete' ] );
911 $localBag->expects( $this->never() )->method(
'set' );
912 $localBag->expects( $this->never() )->method(
'delete' );
914 'cache' => $localBag,
915 'pool' =>
'testcache-hash',
918 $valFunc =
function () {
923 $wanCache->get(
'x' );
924 $wanCache->get(
'x', $ctl, [
'check1' ] );
925 $wanCache->getMulti( [
'x',
'y' ] );
926 $wanCache->getMulti( [
'x',
'y' ], $ctls, [
'check2' ] );
927 $wanCache->getWithSetCallback(
'p', 30, $valFunc );
928 $wanCache->getCheckKeyTime(
'zzz' );
941 $mtime = $ago ? time() - $ago : $ago;
943 $ttl = $this->
cache->adaptiveTTL( $mtime, $maxTTL, $minTTL, $factor );
945 $this->assertGreaterThanOrEqual( $adaptiveTTL - $margin, $ttl );
946 $this->assertLessThanOrEqual( $adaptiveTTL + $margin, $ttl );
948 $ttl = $this->
cache->adaptiveTTL( (
string)$mtime, $maxTTL, $minTTL, $factor );
950 $this->assertGreaterThanOrEqual( $adaptiveTTL - $margin, $ttl );
951 $this->assertLessThanOrEqual( $adaptiveTTL + $margin, $ttl );
956 [ 3600, 900, 30, .2, 720 ],
957 [ 3600, 500, 30, .2, 500 ],
958 [ 3600, 86400, 800, .2, 800 ],
959 [
false, 86400, 800, .2, 800 ],
960 [ null, 86400, 800, .2, 800 ]
set($key, $value, $ttl=0, array $opts=[])
Set the value of a key in cache.
the array() calling protocol came about after MediaWiki 1.4rc1.
testGetWithSetCallback_versions(array $extOpts, $versioned)
getWithSetCallback_versions_provider
static getWithSetCallback_provider()
testAdaptiveTTL($ago, $maxTTL, $minTTL, $factor, $adaptiveTTL)
provideAdaptiveTTL WANObjectCache::adaptiveTTL()
processing should stop and the error should be shown to the user * false
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testCheckKeyInitHoldoff()
WANObjectCache::get() WANObjectCache::processCheckKeys()
testGetMultiCheckKeys()
WANObjectCache::getMulti() WANObjectCache::processCheckKeys()
testSetAndGet($value, $ttl)
provideSetAndGet WANObjectCache::set() WANObjectCache::get() WANObjectCache::makeKey() ...
getMultiWithSetCallback(ArrayIterator $keyedIds, $ttl, callable $callback, array $opts=[])
Method to fetch/regenerate multiple cache keys at once.
touchCheckKey($key, $holdoff=self::HOLDOFF_TTL)
Purge a "check" key from all datacenters, invalidating keys that use it.
get($key, &$curTTL=null, array $checkKeys=[], &$asOf=null)
Fetch the value of a key from cache.
static provideSetAndGet()
testTouchKeys()
WANObjectCache::touchCheckKey() WANObjectCache::resetCheckKey() WANObjectCache::getCheckKeyTime() ...
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 For a description of the see design txt $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
wfRandomString($length=32)
Get a random string containing a number of pseudo-random hex characters.
No-op class for publishing messages into a PubSub system.
getWithSetCallback($key, $ttl, $callback, array $opts=[])
Method to fetch/regenerate cache keys.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
you have access to all of the normal MediaWiki so you can get a DB use the cache
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
testLockTSE()
WANObjectCache::getWithSetCallback() WANObjectCache::doGetWithSetCallback()
static getMultiWithSetCallback_provider()
testStaleSet()
WANObjectCache::set()
static getWithSetCallback_versions_provider()
testLockTSESlow()
WANObjectCache::getWithSetCallback() WANObjectCache::doGetWithSetCallback()
getCheckKeyTime($key)
Fetch the value of a timestamp "check" key.
testSetOver()
WANObjectCache::set()
testGetMulti()
WANObjectCache::getMulti()
testGetWithSetCallback(array $extOpts, $versioned)
getWithSetCallback_provider WANObjectCache::getWithSetCallback() WANObjectCache::doGetWithSetCallback...
testGetMultiWithSetCallback(array $extOpts, $versioned)
getMultiWithSetCallback_provider WANObjectCache::getMultiWithSetCallback() WANObjectCache::makeMultiK...
testSetWithLag()
WANObjectCache::set()
const HOLDOFF_NONE
Idiom for delete() for "no hold-off".
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
testGetWithSeveralCheckKeys()
WANObjectCache::getMulti()
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
delete($key, $ttl=self::HOLDOFF_TTL)
Purge a key from all datacenters.
static provideAdaptiveTTL()
testWritePending()
WANObjectCache::set()
getMulti(array $keys, &$curTTLs=[], array $checkKeys=[], array &$asOfs=[])
Fetch the value of several keys from cache.
testBusyValue()
WANObjectCache::getWithSetCallback() WANObjectCache::doGetWithSetCallback()
testGetNotExists()
WANObjectCache::get() WANObjectCache::makeGlobalKey()
static newFromObject($object)
Return the same object, without access restrictions.
testDelete()
WANObjectCache::delete()
makeMultiKeys(array $entities, callable $keyFunc)