MediaWiki  1.29.2
WANObjectCacheTest.php
Go to the documentation of this file.
1 <?php
2 
3 use Wikimedia\TestingAccessWrapper;
4 
5 class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
7  private $cache;
9  private $internalCache;
10 
11  protected function setUp() {
12  parent::setUp();
13 
14  $this->cache = new WANObjectCache( [
15  'cache' => new HashBagOStuff(),
16  'pool' => 'testcache-hash',
17  'relayer' => new EventRelayerNull( [] )
18  ] );
19 
20  $wanCache = TestingAccessWrapper::newFromObject( $this->cache );
22  $this->internalCache = $wanCache->cache;
23  }
24 
33  public function testSetAndGet( $value, $ttl ) {
34  $curTTL = null;
35  $asOf = null;
36  $key = $this->cache->makeKey( 'x', wfRandomString() );
37 
38  $this->cache->get( $key, $curTTL, [], $asOf );
39  $this->assertNull( $curTTL, "Current TTL is null" );
40  $this->assertNull( $asOf, "Current as-of-time is infinite" );
41 
42  $t = microtime( true );
43  $this->cache->set( $key, $value, $ttl );
44 
45  $this->assertEquals( $value, $this->cache->get( $key, $curTTL, [], $asOf ) );
46  if ( is_infinite( $ttl ) || $ttl == 0 ) {
47  $this->assertTrue( is_infinite( $curTTL ), "Current TTL is infinite" );
48  } else {
49  $this->assertGreaterThan( 0, $curTTL, "Current TTL > 0" );
50  $this->assertLessThanOrEqual( $ttl, $curTTL, "Current TTL < nominal TTL" );
51  }
52  $this->assertGreaterThanOrEqual( $t - 1, $asOf, "As-of-time in range of set() time" );
53  $this->assertLessThanOrEqual( $t + 1, $asOf, "As-of-time in range of set() time" );
54  }
55 
56  public static function provideSetAndGet() {
57  return [
58  [ 14141, 3 ],
59  [ 3535.666, 3 ],
60  [ [], 3 ],
61  [ null, 3 ],
62  [ '0', 3 ],
63  [ (object)[ 'meow' ], 3 ],
64  [ INF, 3 ],
65  [ '', 3 ],
66  [ 'pizzacat', INF ],
67  ];
68  }
69 
74  public function testGetNotExists() {
75  $key = $this->cache->makeGlobalKey( 'y', wfRandomString(), 'p' );
76  $curTTL = null;
77  $value = $this->cache->get( $key, $curTTL );
78 
79  $this->assertFalse( $value, "Non-existing key has false value" );
80  $this->assertNull( $curTTL, "Non-existing key has null current TTL" );
81  }
82 
86  public function testSetOver() {
87  $key = wfRandomString();
88  for ( $i = 0; $i < 3; ++$i ) {
90  $this->cache->set( $key, $value, 3 );
91 
92  $this->assertEquals( $this->cache->get( $key ), $value );
93  }
94  }
95 
99  public function testStaleSet() {
100  $key = wfRandomString();
102  $this->cache->set( $key, $value, 3, [ 'since' => microtime( true ) - 30 ] );
103 
104  $this->assertFalse( $this->cache->get( $key ), "Stale set() value ignored" );
105  }
106 
107  public function testProcessCache() {
108  $hit = 0;
109  $callback = function () use ( &$hit ) {
110  ++$hit;
111  return 42;
112  };
114  $groups = [ 'thiscache:1', 'thatcache:1', 'somecache:1' ];
115 
116  foreach ( $keys as $i => $key ) {
117  $this->cache->getWithSetCallback(
118  $key, 100, $callback, [ 'pcTTL' => 5, 'pcGroup' => $groups[$i] ] );
119  }
120  $this->assertEquals( 3, $hit );
121 
122  foreach ( $keys as $i => $key ) {
123  $this->cache->getWithSetCallback(
124  $key, 100, $callback, [ 'pcTTL' => 5, 'pcGroup' => $groups[$i] ] );
125  }
126  $this->assertEquals( 3, $hit, "Values cached" );
127 
128  foreach ( $keys as $i => $key ) {
129  $this->cache->getWithSetCallback(
130  "$key-2", 100, $callback, [ 'pcTTL' => 5, 'pcGroup' => $groups[$i] ] );
131  }
132  $this->assertEquals( 6, $hit );
133 
134  foreach ( $keys as $i => $key ) {
135  $this->cache->getWithSetCallback(
136  "$key-2", 100, $callback, [ 'pcTTL' => 5, 'pcGroup' => $groups[$i] ] );
137  }
138  $this->assertEquals( 6, $hit, "New values cached" );
139 
140  foreach ( $keys as $i => $key ) {
141  $this->cache->delete( $key );
142  $this->cache->getWithSetCallback(
143  $key, 100, $callback, [ 'pcTTL' => 5, 'pcGroup' => $groups[$i] ] );
144  }
145  $this->assertEquals( 9, $hit, "Values evicted" );
146 
147  $key = reset( $keys );
148  // Get into cache
149  $this->cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
150  $this->cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
151  $this->assertEquals( 10, $hit, "Value cached" );
152  $outerCallback = function () use ( &$callback, $key ) {
153  $v = $this->cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
154 
155  return 43 + $v;
156  };
157  $this->cache->getWithSetCallback( $key, 100, $outerCallback );
158  $this->assertEquals( 11, $hit, "Nested callback value process cache skipped" );
159  }
160 
168  public function testGetWithSetCallback( array $extOpts, $versioned ) {
170 
171  $key = wfRandomString();
173  $cKey1 = wfRandomString();
174  $cKey2 = wfRandomString();
175 
176  $priorValue = null;
177  $priorAsOf = null;
178  $wasSet = 0;
179  $func = function( $old, &$ttl, &$opts, $asOf )
180  use ( &$wasSet, &$priorValue, &$priorAsOf, $value )
181  {
182  ++$wasSet;
183  $priorValue = $old;
184  $priorAsOf = $asOf;
185  $ttl = 20; // override with another value
186  return $value;
187  };
188 
189  $wasSet = 0;
190  $v = $cache->getWithSetCallback( $key, 30, $func, [ 'lockTSE' => 5 ] + $extOpts );
191  $this->assertEquals( $value, $v, "Value returned" );
192  $this->assertEquals( 1, $wasSet, "Value regenerated" );
193  $this->assertFalse( $priorValue, "No prior value" );
194  $this->assertNull( $priorAsOf, "No prior value" );
195 
196  $curTTL = null;
197  $cache->get( $key, $curTTL );
198  $this->assertLessThanOrEqual( 20, $curTTL, 'Current TTL between 19-20 (overriden)' );
199  $this->assertGreaterThanOrEqual( 19, $curTTL, 'Current TTL between 19-20 (overriden)' );
200 
201  $wasSet = 0;
202  $v = $cache->getWithSetCallback( $key, 30, $func, [
203  'lowTTL' => 0,
204  'lockTSE' => 5,
205  ] + $extOpts );
206  $this->assertEquals( $value, $v, "Value returned" );
207  $this->assertEquals( 0, $wasSet, "Value not regenerated" );
208 
209  $priorTime = microtime( true );
210  usleep( 1 );
211  $wasSet = 0;
213  $key, 30, $func, [ 'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
214  );
215  $this->assertEquals( $value, $v, "Value returned" );
216  $this->assertEquals( 1, $wasSet, "Value regenerated due to check keys" );
217  $this->assertEquals( $value, $priorValue, "Has prior value" );
218  $this->assertInternalType( 'float', $priorAsOf, "Has prior value" );
219  $t1 = $cache->getCheckKeyTime( $cKey1 );
220  $this->assertGreaterThanOrEqual( $priorTime, $t1, 'Check keys generated on miss' );
221  $t2 = $cache->getCheckKeyTime( $cKey2 );
222  $this->assertGreaterThanOrEqual( $priorTime, $t2, 'Check keys generated on miss' );
223 
224  $priorTime = microtime( true );
225  $wasSet = 0;
227  $key, 30, $func, [ 'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
228  );
229  $this->assertEquals( $value, $v, "Value returned" );
230  $this->assertEquals( 1, $wasSet, "Value regenerated due to still-recent check keys" );
231  $t1 = $cache->getCheckKeyTime( $cKey1 );
232  $this->assertLessThanOrEqual( $priorTime, $t1, 'Check keys did not change again' );
233  $t2 = $cache->getCheckKeyTime( $cKey2 );
234  $this->assertLessThanOrEqual( $priorTime, $t2, 'Check keys did not change again' );
235 
236  $curTTL = null;
237  $v = $cache->get( $key, $curTTL, [ $cKey1, $cKey2 ] );
238  if ( $versioned ) {
239  $this->assertEquals( $value, $v[$cache::VFLD_DATA], "Value returned" );
240  } else {
241  $this->assertEquals( $value, $v, "Value returned" );
242  }
243  $this->assertLessThanOrEqual( 0, $curTTL, "Value has current TTL < 0 due to check keys" );
244 
245  $wasSet = 0;
246  $key = wfRandomString();
247  $v = $cache->getWithSetCallback( $key, 30, $func, [ 'pcTTL' => 5 ] + $extOpts );
248  $this->assertEquals( $value, $v, "Value returned" );
249  $cache->delete( $key );
250  $v = $cache->getWithSetCallback( $key, 30, $func, [ 'pcTTL' => 5 ] + $extOpts );
251  $this->assertEquals( $value, $v, "Value still returned after deleted" );
252  $this->assertEquals( 1, $wasSet, "Value process cached while deleted" );
253  }
254 
255  public static function getWithSetCallback_provider() {
256  return [
257  [ [], false ],
258  [ [ 'version' => 1 ], true ]
259  ];
260  }
261 
269  public function testGetMultiWithSetCallback( array $extOpts, $versioned ) {
271 
272  $keyA = wfRandomString();
273  $keyB = wfRandomString();
274  $keyC = wfRandomString();
275  $cKey1 = wfRandomString();
276  $cKey2 = wfRandomString();
277 
278  $priorValue = null;
279  $priorAsOf = null;
280  $wasSet = 0;
281  $genFunc = function ( $id, $old, &$ttl, &$opts, $asOf ) use (
282  &$wasSet, &$priorValue, &$priorAsOf
283  ) {
284  ++$wasSet;
285  $priorValue = $old;
286  $priorAsOf = $asOf;
287  $ttl = 20; // override with another value
288  return "@$id$";
289  };
290 
291  $wasSet = 0;
292  $keyedIds = new ArrayIterator( [ $keyA => 3353 ] );
293  $value = "@3353$";
295  $keyedIds, 30, $genFunc, [ 'lockTSE' => 5 ] + $extOpts );
296  $this->assertEquals( $value, $v[$keyA], "Value returned" );
297  $this->assertEquals( 1, $wasSet, "Value regenerated" );
298  $this->assertFalse( $priorValue, "No prior value" );
299  $this->assertNull( $priorAsOf, "No prior value" );
300 
301  $curTTL = null;
302  $cache->get( $keyA, $curTTL );
303  $this->assertLessThanOrEqual( 20, $curTTL, 'Current TTL between 19-20 (overriden)' );
304  $this->assertGreaterThanOrEqual( 19, $curTTL, 'Current TTL between 19-20 (overriden)' );
305 
306  $wasSet = 0;
307  $value = "@efef$";
308  $keyedIds = new ArrayIterator( [ $keyB => 'efef' ] );
310  $keyedIds, 30, $genFunc, [ 'lowTTL' => 0, 'lockTSE' => 5, ] + $extOpts );
311  $this->assertEquals( $value, $v[$keyB], "Value returned" );
312  $this->assertEquals( 1, $wasSet, "Value regenerated" );
314  $keyedIds, 30, $genFunc, [ 'lowTTL' => 0, 'lockTSE' => 5, ] + $extOpts );
315  $this->assertEquals( $value, $v[$keyB], "Value returned" );
316  $this->assertEquals( 1, $wasSet, "Value not regenerated" );
317 
318  $priorTime = microtime( true );
319  usleep( 1 );
320  $wasSet = 0;
321  $keyedIds = new ArrayIterator( [ $keyB => 'efef' ] );
323  $keyedIds, 30, $genFunc, [ 'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
324  );
325  $this->assertEquals( $value, $v[$keyB], "Value returned" );
326  $this->assertEquals( 1, $wasSet, "Value regenerated due to check keys" );
327  $this->assertEquals( $value, $priorValue, "Has prior value" );
328  $this->assertInternalType( 'float', $priorAsOf, "Has prior value" );
329  $t1 = $cache->getCheckKeyTime( $cKey1 );
330  $this->assertGreaterThanOrEqual( $priorTime, $t1, 'Check keys generated on miss' );
331  $t2 = $cache->getCheckKeyTime( $cKey2 );
332  $this->assertGreaterThanOrEqual( $priorTime, $t2, 'Check keys generated on miss' );
333 
334  $priorTime = microtime( true );
335  $value = "@43636$";
336  $wasSet = 0;
337  $keyedIds = new ArrayIterator( [ $keyC => 43636 ] );
339  $keyedIds, 30, $genFunc, [ 'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
340  );
341  $this->assertEquals( $value, $v[$keyC], "Value returned" );
342  $this->assertEquals( 1, $wasSet, "Value regenerated due to still-recent check keys" );
343  $t1 = $cache->getCheckKeyTime( $cKey1 );
344  $this->assertLessThanOrEqual( $priorTime, $t1, 'Check keys did not change again' );
345  $t2 = $cache->getCheckKeyTime( $cKey2 );
346  $this->assertLessThanOrEqual( $priorTime, $t2, 'Check keys did not change again' );
347 
348  $curTTL = null;
349  $v = $cache->get( $keyC, $curTTL, [ $cKey1, $cKey2 ] );
350  if ( $versioned ) {
351  $this->assertEquals( $value, $v[$cache::VFLD_DATA], "Value returned" );
352  } else {
353  $this->assertEquals( $value, $v, "Value returned" );
354  }
355  $this->assertLessThanOrEqual( 0, $curTTL, "Value has current TTL < 0 due to check keys" );
356 
357  $wasSet = 0;
358  $key = wfRandomString();
359  $keyedIds = new ArrayIterator( [ $key => 242424 ] );
361  $keyedIds, 30, $genFunc, [ 'pcTTL' => 5 ] + $extOpts );
362  $this->assertEquals( "@{$keyedIds[$key]}$", $v[$key], "Value returned" );
363  $cache->delete( $key );
364  $keyedIds = new ArrayIterator( [ $key => 242424 ] );
366  $keyedIds, 30, $genFunc, [ 'pcTTL' => 5 ] + $extOpts );
367  $this->assertEquals( "@{$keyedIds[$key]}$", $v[$key], "Value still returned after deleted" );
368  $this->assertEquals( 1, $wasSet, "Value process cached while deleted" );
369 
370  $calls = 0;
371  $ids = [ 1, 2, 3, 4, 5, 6 ];
372  $keyFunc = function ( $id, WANObjectCache $wanCache ) {
373  return $wanCache->makeKey( 'test', $id );
374  };
375  $keyedIds = $cache->makeMultiKeys( $ids, $keyFunc );
376  $genFunc = function ( $id, $oldValue, &$ttl, array &$setops ) use ( &$calls ) {
377  ++$calls;
378 
379  return "val-{$id}";
380  };
381  $values = $cache->getMultiWithSetCallback( $keyedIds, 10, $genFunc );
382 
383  $this->assertEquals(
384  [ "val-1", "val-2", "val-3", "val-4", "val-5", "val-6" ],
385  array_values( $values ),
386  "Correct values in correct order"
387  );
388  $this->assertEquals(
389  array_map( $keyFunc, $ids, array_fill( 0, count( $ids ), $this->cache ) ),
390  array_keys( $values ),
391  "Correct keys in correct order"
392  );
393  $this->assertEquals( count( $ids ), $calls );
394 
395  $cache->getMultiWithSetCallback( $keyedIds, 10, $genFunc );
396  $this->assertEquals( count( $ids ), $calls, "Values cached" );
397  }
398 
399  public static function getMultiWithSetCallback_provider() {
400  return [
401  [ [], false ],
402  [ [ 'version' => 1 ], true ]
403  ];
404  }
405 
410  public function testLockTSE() {
412  $key = wfRandomString();
414 
415  $calls = 0;
416  $func = function() use ( &$calls, $value, $cache, $key ) {
417  ++$calls;
418  // Immediately kill any mutex rather than waiting a second
419  $cache->delete( $cache::MUTEX_KEY_PREFIX . $key );
420  return $value;
421  };
422 
423  $ret = $cache->getWithSetCallback( $key, 30, $func, [ 'lockTSE' => 5 ] );
424  $this->assertEquals( $value, $ret );
425  $this->assertEquals( 1, $calls, 'Value was populated' );
426 
427  // Acquire a lock to verify that getWithSetCallback uses lockTSE properly
428  $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
429 
430  $checkKeys = [ wfRandomString() ]; // new check keys => force misses
431  $ret = $cache->getWithSetCallback( $key, 30, $func,
432  [ 'lockTSE' => 5, 'checkKeys' => $checkKeys ] );
433  $this->assertEquals( $value, $ret, 'Old value used' );
434  $this->assertEquals( 1, $calls, 'Callback was not used' );
435 
436  $cache->delete( $key );
437  $ret = $cache->getWithSetCallback( $key, 30, $func,
438  [ 'lockTSE' => 5, 'checkKeys' => $checkKeys ] );
439  $this->assertEquals( $value, $ret, 'Callback was used; interim saved' );
440  $this->assertEquals( 2, $calls, 'Callback was used; interim saved' );
441 
442  $ret = $cache->getWithSetCallback( $key, 30, $func,
443  [ 'lockTSE' => 5, 'checkKeys' => $checkKeys ] );
444  $this->assertEquals( $value, $ret, 'Callback was not used; used interim' );
445  $this->assertEquals( 2, $calls, 'Callback was not used; used interim' );
446  }
447 
452  public function testLockTSESlow() {
454  $key = wfRandomString();
456 
457  $calls = 0;
458  $func = function( $oldValue, &$ttl, &$setOpts ) use ( &$calls, $value, $cache, $key ) {
459  ++$calls;
460  $setOpts['since'] = microtime( true ) - 10;
461  // Immediately kill any mutex rather than waiting a second
462  $cache->delete( $cache::MUTEX_KEY_PREFIX . $key );
463  return $value;
464  };
465 
466  // Value should be marked as stale due to snapshot lag
467  $curTTL = null;
468  $ret = $cache->getWithSetCallback( $key, 30, $func, [ 'lockTSE' => 5 ] );
469  $this->assertEquals( $value, $ret );
470  $this->assertEquals( $value, $cache->get( $key, $curTTL ), 'Value was populated' );
471  $this->assertLessThan( 0, $curTTL, 'Value has negative curTTL' );
472  $this->assertEquals( 1, $calls, 'Value was generated' );
473 
474  // Acquire a lock to verify that getWithSetCallback uses lockTSE properly
475  $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
476  $ret = $cache->getWithSetCallback( $key, 30, $func, [ 'lockTSE' => 5 ] );
477  $this->assertEquals( $value, $ret );
478  $this->assertEquals( 1, $calls, 'Callback was not used' );
479  }
480 
485  public function testBusyValue() {
487  $key = wfRandomString();
489  $busyValue = wfRandomString();
490 
491  $calls = 0;
492  $func = function() use ( &$calls, $value, $cache, $key ) {
493  ++$calls;
494  // Immediately kill any mutex rather than waiting a second
495  $cache->delete( $cache::MUTEX_KEY_PREFIX . $key );
496  return $value;
497  };
498 
499  $ret = $cache->getWithSetCallback( $key, 30, $func, [ 'busyValue' => $busyValue ] );
500  $this->assertEquals( $value, $ret );
501  $this->assertEquals( 1, $calls, 'Value was populated' );
502 
503  // Acquire a lock to verify that getWithSetCallback uses busyValue properly
504  $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
505 
506  $checkKeys = [ wfRandomString() ]; // new check keys => force misses
507  $ret = $cache->getWithSetCallback( $key, 30, $func,
508  [ 'busyValue' => $busyValue, 'checkKeys' => $checkKeys ] );
509  $this->assertEquals( $value, $ret, 'Callback used' );
510  $this->assertEquals( 2, $calls, 'Callback used' );
511 
512  $ret = $cache->getWithSetCallback( $key, 30, $func,
513  [ 'lockTSE' => 30, 'busyValue' => $busyValue, 'checkKeys' => $checkKeys ] );
514  $this->assertEquals( $value, $ret, 'Old value used' );
515  $this->assertEquals( 2, $calls, 'Callback was not used' );
516 
517  $cache->delete( $key ); // no value at all anymore and still locked
518  $ret = $cache->getWithSetCallback( $key, 30, $func,
519  [ 'busyValue' => $busyValue, 'checkKeys' => $checkKeys ] );
520  $this->assertEquals( $busyValue, $ret, 'Callback was not used; used busy value' );
521  $this->assertEquals( 2, $calls, 'Callback was not used; used busy value' );
522 
523  $this->internalCache->delete( $cache::MUTEX_KEY_PREFIX . $key );
524  $ret = $cache->getWithSetCallback( $key, 30, $func,
525  [ 'lockTSE' => 30, 'busyValue' => $busyValue, 'checkKeys' => $checkKeys ] );
526  $this->assertEquals( $value, $ret, 'Callback was used; saved interim' );
527  $this->assertEquals( 3, $calls, 'Callback was used; saved interim' );
528 
529  $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
530  $ret = $cache->getWithSetCallback( $key, 30, $func,
531  [ 'busyValue' => $busyValue, 'checkKeys' => $checkKeys ] );
532  $this->assertEquals( $value, $ret, 'Callback was not used; used interim' );
533  $this->assertEquals( 3, $calls, 'Callback was not used; used interim' );
534  }
535 
539  public function testGetMulti() {
541 
542  $value1 = [ 'this' => 'is', 'a' => 'test' ];
543  $value2 = [ 'this' => 'is', 'another' => 'test' ];
544 
545  $key1 = wfRandomString();
546  $key2 = wfRandomString();
547  $key3 = wfRandomString();
548 
549  $cache->set( $key1, $value1, 5 );
550  $cache->set( $key2, $value2, 10 );
551 
552  $curTTLs = [];
553  $this->assertEquals(
554  [ $key1 => $value1, $key2 => $value2 ],
555  $cache->getMulti( [ $key1, $key2, $key3 ], $curTTLs ),
556  'Result array populated'
557  );
558 
559  $this->assertEquals( 2, count( $curTTLs ), "Two current TTLs in array" );
560  $this->assertGreaterThan( 0, $curTTLs[$key1], "Key 1 has current TTL > 0" );
561  $this->assertGreaterThan( 0, $curTTLs[$key2], "Key 2 has current TTL > 0" );
562 
563  $cKey1 = wfRandomString();
564  $cKey2 = wfRandomString();
565 
566  $priorTime = microtime( true );
567  usleep( 1 );
568  $curTTLs = [];
569  $this->assertEquals(
570  [ $key1 => $value1, $key2 => $value2 ],
571  $cache->getMulti( [ $key1, $key2, $key3 ], $curTTLs, [ $cKey1, $cKey2 ] ),
572  "Result array populated even with new check keys"
573  );
574  $t1 = $cache->getCheckKeyTime( $cKey1 );
575  $this->assertGreaterThanOrEqual( $priorTime, $t1, 'Check key 1 generated on miss' );
576  $t2 = $cache->getCheckKeyTime( $cKey2 );
577  $this->assertGreaterThanOrEqual( $priorTime, $t2, 'Check key 2 generated on miss' );
578  $this->assertEquals( 2, count( $curTTLs ), "Current TTLs array set" );
579  $this->assertLessThanOrEqual( 0, $curTTLs[$key1], 'Key 1 has current TTL <= 0' );
580  $this->assertLessThanOrEqual( 0, $curTTLs[$key2], 'Key 2 has current TTL <= 0' );
581 
582  usleep( 1 );
583  $curTTLs = [];
584  $this->assertEquals(
585  [ $key1 => $value1, $key2 => $value2 ],
586  $cache->getMulti( [ $key1, $key2, $key3 ], $curTTLs, [ $cKey1, $cKey2 ] ),
587  "Result array still populated even with new check keys"
588  );
589  $this->assertEquals( 2, count( $curTTLs ), "Current TTLs still array set" );
590  $this->assertLessThan( 0, $curTTLs[$key1], 'Key 1 has negative current TTL' );
591  $this->assertLessThan( 0, $curTTLs[$key2], 'Key 2 has negative current TTL' );
592  }
593 
598  public function testGetMultiCheckKeys() {
600 
601  $checkAll = wfRandomString();
602  $check1 = wfRandomString();
603  $check2 = wfRandomString();
604  $check3 = wfRandomString();
605  $value1 = wfRandomString();
606  $value2 = wfRandomString();
607 
608  // Fake initial check key to be set in the past. Otherwise we'd have to sleep for
609  // several seconds during the test to assert the behaviour.
610  foreach ( [ $checkAll, $check1, $check2 ] as $checkKey ) {
612  }
613  usleep( 100 );
614 
615  $cache->set( 'key1', $value1, 10 );
616  $cache->set( 'key2', $value2, 10 );
617 
618  $curTTLs = [];
619  $result = $cache->getMulti( [ 'key1', 'key2', 'key3' ], $curTTLs, [
620  'key1' => $check1,
621  $checkAll,
622  'key2' => $check2,
623  'key3' => $check3,
624  ] );
625  $this->assertEquals(
626  [ 'key1' => $value1, 'key2' => $value2 ],
627  $result,
628  'Initial values'
629  );
630  $this->assertGreaterThanOrEqual( 9.5, $curTTLs['key1'], 'Initial ttls' );
631  $this->assertLessThanOrEqual( 10.5, $curTTLs['key1'], 'Initial ttls' );
632  $this->assertGreaterThanOrEqual( 9.5, $curTTLs['key2'], 'Initial ttls' );
633  $this->assertLessThanOrEqual( 10.5, $curTTLs['key2'], 'Initial ttls' );
634 
635  $cache->touchCheckKey( $check1 );
636 
637  $curTTLs = [];
638  $result = $cache->getMulti( [ 'key1', 'key2', 'key3' ], $curTTLs, [
639  'key1' => $check1,
640  $checkAll,
641  'key2' => $check2,
642  'key3' => $check3,
643  ] );
644  $this->assertEquals(
645  [ 'key1' => $value1, 'key2' => $value2 ],
646  $result,
647  'key1 expired by check1, but value still provided'
648  );
649  $this->assertLessThan( 0, $curTTLs['key1'], 'key1 TTL expired' );
650  $this->assertGreaterThan( 0, $curTTLs['key2'], 'key2 still valid' );
651 
652  $cache->touchCheckKey( $checkAll );
653 
654  $curTTLs = [];
655  $result = $cache->getMulti( [ 'key1', 'key2', 'key3' ], $curTTLs, [
656  'key1' => $check1,
657  $checkAll,
658  'key2' => $check2,
659  'key3' => $check3,
660  ] );
661  $this->assertEquals(
662  [ 'key1' => $value1, 'key2' => $value2 ],
663  $result,
664  'All keys expired by checkAll, but value still provided'
665  );
666  $this->assertLessThan( 0, $curTTLs['key1'], 'key1 expired by checkAll' );
667  $this->assertLessThan( 0, $curTTLs['key2'], 'key2 expired by checkAll' );
668  }
669 
674  public function testCheckKeyInitHoldoff() {
676 
677  for ( $i = 0; $i < 500; ++$i ) {
678  $key = wfRandomString();
679  $checkKey = wfRandomString();
680  // miss, set, hit
681  $cache->get( $key, $curTTL, [ $checkKey ] );
682  $cache->set( $key, 'val', 10 );
683  $curTTL = null;
684  $v = $cache->get( $key, $curTTL, [ $checkKey ] );
685 
686  $this->assertEquals( 'val', $v );
687  $this->assertLessThan( 0, $curTTL, "Step $i: CTL < 0 (miss/set/hit)" );
688  }
689 
690  for ( $i = 0; $i < 500; ++$i ) {
691  $key = wfRandomString();
692  $checkKey = wfRandomString();
693  // set, hit
694  $cache->set( $key, 'val', 10 );
695  $curTTL = null;
696  $v = $cache->get( $key, $curTTL, [ $checkKey ] );
697 
698  $this->assertEquals( 'val', $v );
699  $this->assertLessThan( 0, $curTTL, "Step $i: CTL < 0 (set/hit)" );
700  }
701  }
702 
706  public function testDelete() {
707  $key = wfRandomString();
709  $this->cache->set( $key, $value );
710 
711  $curTTL = null;
712  $v = $this->cache->get( $key, $curTTL );
713  $this->assertEquals( $value, $v, "Key was created with value" );
714  $this->assertGreaterThan( 0, $curTTL, "Existing key has current TTL > 0" );
715 
716  $this->cache->delete( $key );
717 
718  $curTTL = null;
719  $v = $this->cache->get( $key, $curTTL );
720  $this->assertFalse( $v, "Deleted key has false value" );
721  $this->assertLessThan( 0, $curTTL, "Deleted key has current TTL < 0" );
722 
723  $this->cache->set( $key, $value . 'more' );
724  $v = $this->cache->get( $key, $curTTL );
725  $this->assertFalse( $v, "Deleted key is tombstoned and has false value" );
726  $this->assertLessThan( 0, $curTTL, "Deleted key is tombstoned and has current TTL < 0" );
727 
728  $this->cache->set( $key, $value );
729  $this->cache->delete( $key, WANObjectCache::HOLDOFF_NONE );
730 
731  $curTTL = null;
732  $v = $this->cache->get( $key, $curTTL );
733  $this->assertFalse( $v, "Deleted key has false value" );
734  $this->assertNull( $curTTL, "Deleted key has null current TTL" );
735 
736  $this->cache->set( $key, $value );
737  $v = $this->cache->get( $key, $curTTL );
738  $this->assertEquals( $value, $v, "Key was created with value" );
739  $this->assertGreaterThan( 0, $curTTL, "Existing key has current TTL > 0" );
740  }
741 
747  public function testGetWithSetCallback_versions( array $extOpts, $versioned ) {
749 
750  $key = wfRandomString();
752 
753  $wasSet = 0;
754  $func = function( $old, &$ttl ) use ( &$wasSet, $value ) {
755  ++$wasSet;
756  return $value;
757  };
758 
759  // Set the main key (version N if versioned)
760  $wasSet = 0;
761  $v = $cache->getWithSetCallback( $key, 30, $func, $extOpts );
762  $this->assertEquals( $value, $v, "Value returned" );
763  $this->assertEquals( 1, $wasSet, "Value regenerated" );
764  $cache->getWithSetCallback( $key, 30, $func, $extOpts );
765  $this->assertEquals( 1, $wasSet, "Value not regenerated" );
766  // Set the key for version N+1 (if versioned)
767  if ( $versioned ) {
768  $verOpts = [ 'version' => $extOpts['version'] + 1 ];
769 
770  $wasSet = 0;
771  $v = $cache->getWithSetCallback( $key, 30, $func, $verOpts + $extOpts );
772  $this->assertEquals( $value, $v, "Value returned" );
773  $this->assertEquals( 1, $wasSet, "Value regenerated" );
774 
775  $wasSet = 0;
776  $v = $cache->getWithSetCallback( $key, 30, $func, $verOpts + $extOpts );
777  $this->assertEquals( $value, $v, "Value returned" );
778  $this->assertEquals( 0, $wasSet, "Value not regenerated" );
779  }
780 
781  $wasSet = 0;
782  $cache->getWithSetCallback( $key, 30, $func, $extOpts );
783  $this->assertEquals( 0, $wasSet, "Value not regenerated" );
784 
785  $wasSet = 0;
786  $cache->delete( $key );
787  $v = $cache->getWithSetCallback( $key, 30, $func, $extOpts );
788  $this->assertEquals( $value, $v, "Value returned" );
789  $this->assertEquals( 1, $wasSet, "Value regenerated" );
790 
791  if ( $versioned ) {
792  $wasSet = 0;
793  $verOpts = [ 'version' => $extOpts['version'] + 1 ];
794  $v = $cache->getWithSetCallback( $key, 30, $func, $verOpts + $extOpts );
795  $this->assertEquals( $value, $v, "Value returned" );
796  $this->assertEquals( 1, $wasSet, "Value regenerated" );
797  }
798  }
799 
800  public static function getWithSetCallback_versions_provider() {
801  return [
802  [ [], false ],
803  [ [ 'version' => 1 ], true ]
804  ];
805  }
806 
812  public function testTouchKeys() {
813  $key = wfRandomString();
814 
815  $priorTime = microtime( true );
816  usleep( 100 );
817  $t0 = $this->cache->getCheckKeyTime( $key );
818  $this->assertGreaterThanOrEqual( $priorTime, $t0, 'Check key auto-created' );
819 
820  $priorTime = microtime( true );
821  usleep( 100 );
822  $this->cache->touchCheckKey( $key );
823  $t1 = $this->cache->getCheckKeyTime( $key );
824  $this->assertGreaterThanOrEqual( $priorTime, $t1, 'Check key created' );
825 
826  $t2 = $this->cache->getCheckKeyTime( $key );
827  $this->assertEquals( $t1, $t2, 'Check key time did not change' );
828 
829  usleep( 100 );
830  $this->cache->touchCheckKey( $key );
831  $t3 = $this->cache->getCheckKeyTime( $key );
832  $this->assertGreaterThan( $t2, $t3, 'Check key time increased' );
833 
834  $t4 = $this->cache->getCheckKeyTime( $key );
835  $this->assertEquals( $t3, $t4, 'Check key time did not change' );
836 
837  usleep( 100 );
838  $this->cache->resetCheckKey( $key );
839  $t5 = $this->cache->getCheckKeyTime( $key );
840  $this->assertGreaterThan( $t4, $t5, 'Check key time increased' );
841 
842  $t6 = $this->cache->getCheckKeyTime( $key );
843  $this->assertEquals( $t5, $t6, 'Check key time did not change' );
844  }
845 
849  public function testGetWithSeveralCheckKeys() {
850  $key = wfRandomString();
851  $tKey1 = wfRandomString();
852  $tKey2 = wfRandomString();
853  $value = 'meow';
854 
855  // Two check keys are newer (given hold-off) than $key, another is older
856  $this->internalCache->set(
858  WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 3 )
859  );
860  $this->internalCache->set(
862  WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 5 )
863  );
864  $this->internalCache->set(
866  WANObjectCache::PURGE_VAL_PREFIX . ( microtime( true ) - 30 )
867  );
868  $this->cache->set( $key, $value, 30 );
869 
870  $curTTL = null;
871  $v = $this->cache->get( $key, $curTTL, [ $tKey1, $tKey2 ] );
872  $this->assertEquals( $value, $v, "Value matches" );
873  $this->assertLessThan( -4.9, $curTTL, "Correct CTL" );
874  $this->assertGreaterThan( -5.1, $curTTL, "Correct CTL" );
875  }
876 
881  public function testReap() {
882  $vKey1 = wfRandomString();
883  $vKey2 = wfRandomString();
884  $tKey1 = wfRandomString();
885  $tKey2 = wfRandomString();
886  $value = 'moo';
887 
888  $knownPurge = time() - 60;
889  $goodTime = microtime( true ) - 5;
890  $badTime = microtime( true ) - 300;
891 
892  $this->internalCache->set(
894  [
897  WANObjectCache::FLD_TTL => 3600,
898  WANObjectCache::FLD_TIME => $goodTime
899  ]
900  );
901  $this->internalCache->set(
903  [
906  WANObjectCache::FLD_TTL => 3600,
907  WANObjectCache::FLD_TIME => $badTime
908  ]
909  );
910  $this->internalCache->set(
913  );
914  $this->internalCache->set(
917  );
918 
919  $this->assertEquals( $value, $this->cache->get( $vKey1 ) );
920  $this->assertEquals( $value, $this->cache->get( $vKey2 ) );
921  $this->cache->reap( $vKey1, $knownPurge, $bad1 );
922  $this->cache->reap( $vKey2, $knownPurge, $bad2 );
923 
924  $this->assertFalse( $bad1 );
925  $this->assertTrue( $bad2 );
926 
927  $this->cache->reapCheckKey( $tKey1, $knownPurge, $tBad1 );
928  $this->cache->reapCheckKey( $tKey2, $knownPurge, $tBad2 );
929  $this->assertFalse( $tBad1 );
930  $this->assertTrue( $tBad2 );
931  }
932 
936  public function testSetWithLag() {
937  $value = 1;
938 
939  $key = wfRandomString();
940  $opts = [ 'lag' => 300, 'since' => microtime( true ) ];
941  $this->cache->set( $key, $value, 30, $opts );
942  $this->assertEquals( $value, $this->cache->get( $key ), "Rep-lagged value written." );
943 
944  $key = wfRandomString();
945  $opts = [ 'lag' => 0, 'since' => microtime( true ) - 300 ];
946  $this->cache->set( $key, $value, 30, $opts );
947  $this->assertEquals( false, $this->cache->get( $key ), "Trx-lagged value not written." );
948 
949  $key = wfRandomString();
950  $opts = [ 'lag' => 5, 'since' => microtime( true ) - 5 ];
951  $this->cache->set( $key, $value, 30, $opts );
952  $this->assertEquals( false, $this->cache->get( $key ), "Lagged value not written." );
953  }
954 
958  public function testWritePending() {
959  $value = 1;
960 
961  $key = wfRandomString();
962  $opts = [ 'pending' => true ];
963  $this->cache->set( $key, $value, 30, $opts );
964  $this->assertEquals( false, $this->cache->get( $key ), "Pending value not written." );
965  }
966 
967  public function testMcRouterSupport() {
968  $localBag = $this->getMockBuilder( 'EmptyBagOStuff' )
969  ->setMethods( [ 'set', 'delete' ] )->getMock();
970  $localBag->expects( $this->never() )->method( 'set' );
971  $localBag->expects( $this->never() )->method( 'delete' );
972  $wanCache = new WANObjectCache( [
973  'cache' => $localBag,
974  'pool' => 'testcache-hash',
975  'relayer' => new EventRelayerNull( [] )
976  ] );
977  $valFunc = function () {
978  return 1;
979  };
980 
981  // None of these should use broadcasting commands (e.g. SET, DELETE)
982  $wanCache->get( 'x' );
983  $wanCache->get( 'x', $ctl, [ 'check1' ] );
984  $wanCache->getMulti( [ 'x', 'y' ] );
985  $wanCache->getMulti( [ 'x', 'y' ], $ctls, [ 'check2' ] );
986  $wanCache->getWithSetCallback( 'p', 30, $valFunc );
987  $wanCache->getCheckKeyTime( 'zzz' );
988  $wanCache->reap( 'x', time() - 300 );
989  $wanCache->reap( 'zzz', time() - 300 );
990  }
991 
1001  public function testAdaptiveTTL( $ago, $maxTTL, $minTTL, $factor, $adaptiveTTL ) {
1002  $mtime = $ago ? time() - $ago : $ago;
1003  $margin = 5;
1004  $ttl = $this->cache->adaptiveTTL( $mtime, $maxTTL, $minTTL, $factor );
1005 
1006  $this->assertGreaterThanOrEqual( $adaptiveTTL - $margin, $ttl );
1007  $this->assertLessThanOrEqual( $adaptiveTTL + $margin, $ttl );
1008 
1009  $ttl = $this->cache->adaptiveTTL( (string)$mtime, $maxTTL, $minTTL, $factor );
1010 
1011  $this->assertGreaterThanOrEqual( $adaptiveTTL - $margin, $ttl );
1012  $this->assertLessThanOrEqual( $adaptiveTTL + $margin, $ttl );
1013  }
1014 
1015  public static function provideAdaptiveTTL() {
1016  return [
1017  [ 3600, 900, 30, .2, 720 ],
1018  [ 3600, 500, 30, .2, 500 ],
1019  [ 3600, 86400, 800, .2, 800 ],
1020  [ false, 86400, 800, .2, 800 ],
1021  [ null, 86400, 800, .2, 800 ]
1022  ];
1023  }
1024 }
WANObjectCacheTest\testStaleSet
testStaleSet()
WANObjectCache::set()
Definition: WANObjectCacheTest.php:99
WANObjectCacheTest\testSetWithLag
testSetWithLag()
WANObjectCache::set()
Definition: WANObjectCacheTest.php:936
WANObjectCacheTest\testSetOver
testSetOver()
WANObjectCache::set()
Definition: WANObjectCacheTest.php:86
object
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
Definition: globals.txt:25
WANObjectCacheTest\getWithSetCallback_versions_provider
static getWithSetCallback_versions_provider()
Definition: WANObjectCacheTest.php:800
WANObjectCache\VALUE_KEY_PREFIX
const VALUE_KEY_PREFIX
Definition: WANObjectCache.php:159
WANObjectCacheTest\testGetMultiWithSetCallback
testGetMultiWithSetCallback(array $extOpts, $versioned)
getMultiWithSetCallback_provider WANObjectCache::getMultiWithSetCallback() WANObjectCache::makeMultiK...
Definition: WANObjectCacheTest.php:269
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
WANObjectCacheTest\testAdaptiveTTL
testAdaptiveTTL( $ago, $maxTTL, $minTTL, $factor, $adaptiveTTL)
provideAdaptiveTTL WANObjectCache::adaptiveTTL()
Definition: WANObjectCacheTest.php:1001
captcha-old.count
count
Definition: captcha-old.py:225
WANObjectCache\FLD_VERSION
const FLD_VERSION
Definition: WANObjectCache.php:143
WANObjectCache\FLD_VALUE
const FLD_VALUE
Definition: WANObjectCache.php:144
WANObjectCacheTest\testGetWithSetCallback
testGetWithSetCallback(array $extOpts, $versioned)
getWithSetCallback_provider WANObjectCache::getWithSetCallback() WANObjectCache::doGetWithSetCallback...
Definition: WANObjectCacheTest.php:168
$result
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:Array with elements of the form "language:title" in the order that they will be output. & $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
Definition: hooks.txt:1954
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
EventRelayerNull
No-op class for publishing messages into a PubSub system.
Definition: EventRelayerNull.php:25
WANObjectCache\makeMultiKeys
makeMultiKeys(array $entities, callable $keyFunc)
Definition: WANObjectCache.php:1220
WANObjectCacheTest\provideAdaptiveTTL
static provideAdaptiveTTL()
Definition: WANObjectCacheTest.php:1015
WANObjectCache\getMultiWithSetCallback
getMultiWithSetCallback(ArrayIterator $keyedIds, $ttl, callable $callback, array $opts=[])
Method to fetch/regenerate multiple cache keys at once.
Definition: WANObjectCache.php:1103
WANObjectCacheTest\getWithSetCallback_provider
static getWithSetCallback_provider()
Definition: WANObjectCacheTest.php:255
WANObjectCache\set
set( $key, $value, $ttl=0, array $opts=[])
Set the value of a key in cache.
Definition: WANObjectCache.php:433
WANObjectCacheTest\testGetWithSeveralCheckKeys
testGetWithSeveralCheckKeys()
WANObjectCache::getMulti()
Definition: WANObjectCacheTest.php:849
WANObjectCacheTest\testWritePending
testWritePending()
WANObjectCache::set()
Definition: WANObjectCacheTest.php:958
WANObjectCacheTest\testSetAndGet
testSetAndGet( $value, $ttl)
provideSetAndGet WANObjectCache::set() WANObjectCache::get() WANObjectCache::makeKey()
Definition: WANObjectCacheTest.php:33
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
php
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
Definition: injection.txt:35
WANObjectCache\getCheckKeyTime
getCheckKeyTime( $key)
Fetch the value of a timestamp "check" key.
Definition: WANObjectCache.php:573
WANObjectCacheTest\testProcessCache
testProcessCache()
Definition: WANObjectCacheTest.php:107
WANObjectCache\TIME_KEY_PREFIX
const TIME_KEY_PREFIX
Definition: WANObjectCache.php:161
WANObjectCache\FLD_TIME
const FLD_TIME
Definition: WANObjectCache.php:146
WANObjectCacheTest\testGetNotExists
testGetNotExists()
WANObjectCache::get() WANObjectCache::makeGlobalKey()
Definition: WANObjectCacheTest.php:74
WANObjectCache\getWithSetCallback
getWithSetCallback( $key, $ttl, $callback, array $opts=[])
Method to fetch/regenerate cache keys.
Definition: WANObjectCache.php:854
WANObjectCacheTest\testDelete
testDelete()
WANObjectCache::delete()
Definition: WANObjectCacheTest.php:706
WANObjectCache\touchCheckKey
touchCheckKey( $key, $holdoff=self::HOLDOFF_TTL)
Purge a "check" key from all datacenters, invalidating keys that use it.
Definition: WANObjectCache.php:625
WANObjectCacheTest\$internalCache
$internalCache
Definition: WANObjectCacheTest.php:9
WANObjectCacheTest\setUp
setUp()
Definition: WANObjectCacheTest.php:11
WANObjectCacheTest\testCheckKeyInitHoldoff
testCheckKeyInitHoldoff()
WANObjectCache::get() WANObjectCache::processCheckKeys()
Definition: WANObjectCacheTest.php:674
WANObjectCache\get
get( $key, &$curTTL=null, array $checkKeys=[], &$asOf=null)
Fetch the value of a key from cache.
Definition: WANObjectCache.php:248
$value
$value
Definition: styleTest.css.php:45
WANObjectCacheTest\testGetMultiCheckKeys
testGetMultiCheckKeys()
WANObjectCache::getMulti() WANObjectCache::processCheckKeys()
Definition: WANObjectCacheTest.php:598
WANObjectCacheTest\testLockTSESlow
testLockTSESlow()
WANObjectCache::getWithSetCallback() WANObjectCache::doGetWithSetCallback()
Definition: WANObjectCacheTest.php:452
WANObjectCacheTest\testBusyValue
testBusyValue()
WANObjectCache::getWithSetCallback() WANObjectCache::doGetWithSetCallback()
Definition: WANObjectCacheTest.php:485
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:81
WANObjectCache\VERSION
const VERSION
Cache format version number.
Definition: WANObjectCache.php:141
$ret
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
Definition: hooks.txt:1956
WANObjectCache\getMulti
getMulti(array $keys, &$curTTLs=[], array $checkKeys=[], array &$asOfs=[])
Fetch the value of several keys from cache.
Definition: WANObjectCache.php:270
WANObjectCacheTest\$cache
WANObjectCache $cache
Definition: WANObjectCacheTest.php:7
WANObjectCacheTest\testTouchKeys
testTouchKeys()
WANObjectCache::touchCheckKey() WANObjectCache::resetCheckKey() WANObjectCache::getCheckKeyTime()
Definition: WANObjectCacheTest.php:812
WANObjectCacheTest\testLockTSE
testLockTSE()
WANObjectCache::getWithSetCallback() WANObjectCache::doGetWithSetCallback()
Definition: WANObjectCacheTest.php:410
WANObjectCacheTest\testMcRouterSupport
testMcRouterSupport()
Definition: WANObjectCacheTest.php:967
WANObjectCache\PURGE_VAL_PREFIX
const PURGE_VAL_PREFIX
Definition: WANObjectCache.php:164
as
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
Definition: distributors.txt:9
WANObjectCacheTest\testReap
testReap()
WANObjectCache::reap() WANObjectCache::reapCheckKey()
Definition: WANObjectCacheTest.php:881
$keys
$keys
Definition: testCompression.php:65
WANObjectCacheTest\provideSetAndGet
static provideSetAndGet()
Definition: WANObjectCacheTest.php:56
WANObjectCacheTest\testGetMulti
testGetMulti()
WANObjectCache::getMulti()
Definition: WANObjectCacheTest.php:539
WANObjectCache\HOLDOFF_NONE
const HOLDOFF_NONE
Idiom for delete() for "no hold-off".
Definition: WANObjectCache.php:133
true
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
Definition: hooks.txt:1956
$t
$t
Definition: testCompression.php:67
WANObjectCacheTest\getMultiWithSetCallback_provider
static getMultiWithSetCallback_provider()
Definition: WANObjectCacheTest.php:399
WANObjectCache\FLD_TTL
const FLD_TTL
Definition: WANObjectCache.php:145
WANObjectCache\delete
delete( $key, $ttl=self::HOLDOFF_TTL)
Purge a key from all datacenters.
Definition: WANObjectCache.php:540
WANObjectCacheTest\testGetWithSetCallback_versions
testGetWithSetCallback_versions(array $extOpts, $versioned)
getWithSetCallback_versions_provider
Definition: WANObjectCacheTest.php:747
array
the array() calling protocol came about after MediaWiki 1.4rc1.
WANObjectCacheTest
Definition: WANObjectCacheTest.php:5
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:336