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" );
42 $t = microtime(
true );
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" );
49 $this->assertGreaterThan( 0, $curTTL,
"Current TTL > 0" );
50 $this->assertLessThanOrEqual( $ttl, $curTTL,
"Current TTL < nominal TTL" );
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" );
109 $callback =
function () use ( &$hit ) {
114 $groups = [
'thiscache:1',
'thatcache:1',
'somecache:1' ];
116 foreach (
$keys as $i => $key ) {
117 $this->
cache->getWithSetCallback(
118 $key, 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
120 $this->assertEquals( 3, $hit );
122 foreach (
$keys as $i => $key ) {
123 $this->
cache->getWithSetCallback(
124 $key, 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
126 $this->assertEquals( 3, $hit,
"Values cached" );
128 foreach (
$keys as $i => $key ) {
129 $this->
cache->getWithSetCallback(
130 "$key-2", 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
132 $this->assertEquals( 6, $hit );
134 foreach (
$keys as $i => $key ) {
135 $this->
cache->getWithSetCallback(
136 "$key-2", 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
138 $this->assertEquals( 6, $hit,
"New values cached" );
140 foreach (
$keys as $i => $key ) {
141 $this->
cache->delete( $key );
142 $this->
cache->getWithSetCallback(
143 $key, 100, $callback, [
'pcTTL' => 5,
'pcGroup' => $groups[$i] ] );
145 $this->assertEquals( 9, $hit,
"Values evicted" );
147 $key = reset(
$keys );
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 ] );
157 $this->
cache->getWithSetCallback( $key, 100, $outerCallback );
158 $this->assertEquals( 11, $hit,
"Nested callback value process cache skipped" );
179 $func =
function ( $old, &$ttl, &$opts, $asOf )
180 use ( &$wasSet, &$priorValue, &$priorAsOf,
$value )
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" );
198 $this->assertLessThanOrEqual( 20, $curTTL,
'Current TTL between 19-20 (overriden)' );
199 $this->assertGreaterThanOrEqual( 19, $curTTL,
'Current TTL between 19-20 (overriden)' );
206 $this->assertEquals(
$value, $v,
"Value returned" );
207 $this->assertEquals( 0, $wasSet,
"Value not regenerated" );
209 $priorTime = microtime(
true );
213 $key, 30, $func, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
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" );
220 $this->assertGreaterThanOrEqual( $priorTime, $t1,
'Check keys generated on miss' );
222 $this->assertGreaterThanOrEqual( $priorTime, $t2,
'Check keys generated on miss' );
224 $priorTime = microtime(
true );
227 $key, 30, $func, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
229 $this->assertEquals(
$value, $v,
"Value returned" );
230 $this->assertEquals( 1, $wasSet,
"Value regenerated due to still-recent check keys" );
232 $this->assertLessThanOrEqual( $priorTime, $t1,
'Check keys did not change again' );
234 $this->assertLessThanOrEqual( $priorTime, $t2,
'Check keys did not change again' );
237 $v =
$cache->
get( $key, $curTTL, [ $cKey1, $cKey2 ] );
239 $this->assertEquals(
$value, $v[$cache::VFLD_DATA],
"Value returned" );
241 $this->assertEquals(
$value, $v,
"Value returned" );
243 $this->assertLessThanOrEqual( 0, $curTTL,
"Value has current TTL < 0 due to check keys" );
248 $this->assertEquals(
$value, $v,
"Value returned" );
251 $this->assertEquals(
$value, $v,
"Value still returned after deleted" );
252 $this->assertEquals( 1, $wasSet,
"Value process cached while deleted" );
281 $genFunc =
function ( $id, $old, &$ttl, &$opts, $asOf ) use (
282 &$wasSet, &$priorValue, &$priorAsOf
292 $keyedIds =
new ArrayIterator( [ $keyA => 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" );
303 $this->assertLessThanOrEqual( 20, $curTTL,
'Current TTL between 19-20 (overriden)' );
304 $this->assertGreaterThanOrEqual( 19, $curTTL,
'Current TTL between 19-20 (overriden)' );
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" );
315 $keyedIds, 30, $genFunc, [
'lowTTL' => 0,
'lockTSE' => 5, ] + $extOpts );
316 $this->assertEquals(
$value, $v[$keyB],
"Value returned" );
317 $this->assertEquals( 1, $wasSet,
"Value not regenerated" );
320 $priorTime = microtime(
true );
323 $keyedIds =
new ArrayIterator( [ $keyB =>
'efef' ] );
325 $keyedIds, 30, $genFunc, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
327 $this->assertEquals(
$value, $v[$keyB],
"Value returned" );
328 $this->assertEquals( 1, $wasSet,
"Value regenerated due to check keys" );
329 $this->assertEquals(
$value, $priorValue,
"Has prior value" );
330 $this->assertInternalType(
'float', $priorAsOf,
"Has prior value" );
332 $this->assertGreaterThanOrEqual( $priorTime, $t1,
'Check keys generated on miss' );
334 $this->assertGreaterThanOrEqual( $priorTime, $t2,
'Check keys generated on miss' );
336 $priorTime = microtime(
true );
339 $keyedIds =
new ArrayIterator( [ $keyC => 43636 ] );
341 $keyedIds, 30, $genFunc, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
343 $this->assertEquals(
$value, $v[$keyC],
"Value returned" );
344 $this->assertEquals( 1, $wasSet,
"Value regenerated due to still-recent check keys" );
346 $this->assertLessThanOrEqual( $priorTime, $t1,
'Check keys did not change again' );
348 $this->assertLessThanOrEqual( $priorTime, $t2,
'Check keys did not change again' );
351 $v =
$cache->
get( $keyC, $curTTL, [ $cKey1, $cKey2 ] );
353 $this->assertEquals(
$value, $v[$cache::VFLD_DATA],
"Value returned" );
355 $this->assertEquals(
$value, $v,
"Value returned" );
357 $this->assertLessThanOrEqual( 0, $curTTL,
"Value has current TTL < 0 due to check keys" );
361 $keyedIds =
new ArrayIterator( [ $key => 242424 ] );
363 $keyedIds, 30, $genFunc, [
'pcTTL' => 5 ] + $extOpts );
364 $this->assertEquals(
"@{$keyedIds[$key]}$", $v[$key],
"Value returned" );
366 $keyedIds =
new ArrayIterator( [ $key => 242424 ] );
368 $keyedIds, 30, $genFunc, [
'pcTTL' => 5 ] + $extOpts );
369 $this->assertEquals(
"@{$keyedIds[$key]}$", $v[$key],
"Value still returned after deleted" );
370 $this->assertEquals( 1, $wasSet,
"Value process cached while deleted" );
373 $ids = [ 1, 2, 3, 4, 5, 6 ];
375 return $wanCache->makeKey(
'test', $id );
378 $genFunc =
function ( $id, $oldValue, &$ttl, array &$setops ) use ( &$calls ) {
386 [
"val-1",
"val-2",
"val-3",
"val-4",
"val-5",
"val-6" ],
387 array_values( $values ),
388 "Correct values in correct order"
391 array_map( $keyFunc, $ids, array_fill( 0, count( $ids ), $this->
cache ) ),
392 array_keys( $values ),
393 "Correct keys in correct order"
395 $this->assertEquals( count( $ids ), $calls );
398 $this->assertEquals( count( $ids ), $calls,
"Values cached" );
401 $localBag = $this->getMockBuilder(
'HashBagOStuff' )
402 ->setMethods( [
'getMulti' ] )->getMock();
403 $localBag->expects( $this->exactly( 1 ) )->method(
'getMulti' )->willReturn( [
404 WANObjectCache::VALUE_KEY_PREFIX .
'k1' =>
'val-id1',
405 WANObjectCache::VALUE_KEY_PREFIX .
'k2' =>
'val-id2'
407 $wanCache =
new WANObjectCache( [
'cache' => $localBag,
'pool' =>
'testcache-hash' ] );
410 $keyedIds =
new ArrayIterator( [
'k1' =>
'id1',
'k2' =>
'id2' ] );
412 [
'k1' =>
'val-id1',
'k2' =>
'val-id2' ],
413 $wanCache->getMultiWithSetCallback( $keyedIds, 10, $genFunc, [
'pcTTL' => 5 ] )
417 [
'k1' =>
'val-id1',
'k2' =>
'val-id2' ],
418 $wanCache->getMultiWithSetCallback( $keyedIds, 10, $genFunc, [
'pcTTL' => 5 ] )
446 $genFunc =
function ( array $ids, array &$ttls, array &$setOpts ) use (
447 &$wasSet, &$priorValue, &$priorAsOf
450 foreach ( $ids as $id ) {
452 $newValues[$id] =
"@$id$";
460 $keyedIds =
new ArrayIterator( [ $keyA => 3353 ] );
463 $keyedIds, 30, $genFunc, $extOpts );
464 $this->assertEquals(
$value, $v[$keyA],
"Value returned" );
465 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
469 $this->assertLessThanOrEqual( 20, $curTTL,
'Current TTL between 19-20 (overriden)' );
470 $this->assertGreaterThanOrEqual( 19, $curTTL,
'Current TTL between 19-20 (overriden)' );
474 $keyedIds =
new ArrayIterator( [ $keyB =>
'efef' ] );
476 $keyedIds, 30, $genFunc, [
'lowTTL' => 0 ] + $extOpts );
477 $this->assertEquals(
$value, $v[$keyB],
"Value returned" );
478 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
481 $keyedIds, 30, $genFunc, [
'lowTTL' => 0 ] + $extOpts );
482 $this->assertEquals(
$value, $v[$keyB],
"Value returned" );
483 $this->assertEquals( 1, $wasSet,
"Value not regenerated" );
486 $priorTime = microtime(
true );
489 $keyedIds =
new ArrayIterator( [ $keyB =>
'efef' ] );
491 $keyedIds, 30, $genFunc, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
493 $this->assertEquals(
$value, $v[$keyB],
"Value returned" );
494 $this->assertEquals( 1, $wasSet,
"Value regenerated due to check keys" );
496 $this->assertGreaterThanOrEqual( $priorTime, $t1,
'Check keys generated on miss' );
498 $this->assertGreaterThanOrEqual( $priorTime, $t2,
'Check keys generated on miss' );
500 $priorTime = microtime(
true );
503 $keyedIds =
new ArrayIterator( [ $keyC => 43636 ] );
505 $keyedIds, 30, $genFunc, [
'checkKeys' => [ $cKey1, $cKey2 ] ] + $extOpts
507 $this->assertEquals(
$value, $v[$keyC],
"Value returned" );
508 $this->assertEquals( 1, $wasSet,
"Value regenerated due to still-recent check keys" );
510 $this->assertLessThanOrEqual( $priorTime, $t1,
'Check keys did not change again' );
512 $this->assertLessThanOrEqual( $priorTime, $t2,
'Check keys did not change again' );
515 $v =
$cache->
get( $keyC, $curTTL, [ $cKey1, $cKey2 ] );
517 $this->assertEquals(
$value, $v[$cache::VFLD_DATA],
"Value returned" );
519 $this->assertEquals(
$value, $v,
"Value returned" );
521 $this->assertLessThanOrEqual( 0, $curTTL,
"Value has current TTL < 0 due to check keys" );
525 $keyedIds =
new ArrayIterator( [ $key => 242424 ] );
527 $keyedIds, 30, $genFunc, [
'pcTTL' => 5 ] + $extOpts );
528 $this->assertEquals(
"@{$keyedIds[$key]}$", $v[$key],
"Value returned" );
530 $keyedIds =
new ArrayIterator( [ $key => 242424 ] );
532 $keyedIds, 30, $genFunc, [
'pcTTL' => 5 ] + $extOpts );
533 $this->assertEquals(
"@{$keyedIds[$key]}$", $v[$key],
"Value still returned after deleted" );
534 $this->assertEquals( 1, $wasSet,
"Value process cached while deleted" );
537 $ids = [ 1, 2, 3, 4, 5, 6 ];
539 return $wanCache->makeKey(
'test', $id );
542 $genFunc =
function ( array $ids, array &$ttls, array &$setOpts ) use ( &$calls ) {
544 foreach ( $ids as $id ) {
546 $newValues[$id] =
"val-{$id}";
554 [
"val-1",
"val-2",
"val-3",
"val-4",
"val-5",
"val-6" ],
555 array_values( $values ),
556 "Correct values in correct order"
559 array_map( $keyFunc, $ids, array_fill( 0, count( $ids ), $this->
cache ) ),
560 array_keys( $values ),
561 "Correct keys in correct order"
563 $this->assertEquals( count( $ids ), $calls );
566 $this->assertEquals( count( $ids ), $calls,
"Values cached" );
662 $func =
function () use ( &$calls,
$value,
$cache, $key ) {
671 $this->assertEquals( 1, $calls,
'Value was populated' );
674 $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
678 [
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
679 $this->assertEquals(
$value,
$ret,
'Callback used' );
680 $this->assertEquals( 2, $calls,
'Callback used' );
683 [
'lockTSE' => 30,
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
684 $this->assertEquals(
$value,
$ret,
'Old value used' );
685 $this->assertEquals( 2, $calls,
'Callback was not used' );
689 [
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
690 $this->assertEquals( $busyValue,
$ret,
'Callback was not used; used busy value' );
691 $this->assertEquals( 2, $calls,
'Callback was not used; used busy value' );
693 $this->internalCache->delete( $cache::MUTEX_KEY_PREFIX . $key );
695 [
'lockTSE' => 30,
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
696 $this->assertEquals(
$value,
$ret,
'Callback was used; saved interim' );
697 $this->assertEquals( 3, $calls,
'Callback was used; saved interim' );
699 $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 );
701 [
'busyValue' => $busyValue,
'checkKeys' => $checkKeys ] );
702 $this->assertEquals(
$value,
$ret,
'Callback was not used; used interim' );
703 $this->assertEquals( 3, $calls,
'Callback was not used; used interim' );
712 $value1 = [
'this' =>
'is',
'a' =>
'test' ];
713 $value2 = [
'this' =>
'is',
'another' =>
'test' ];
724 [ $key1 => $value1, $key2 => $value2 ],
726 'Result array populated'
729 $this->assertEquals( 2, count( $curTTLs ),
"Two current TTLs in array" );
730 $this->assertGreaterThan( 0, $curTTLs[$key1],
"Key 1 has current TTL > 0" );
731 $this->assertGreaterThan( 0, $curTTLs[$key2],
"Key 2 has current TTL > 0" );
736 $priorTime = microtime(
true );
740 [ $key1 => $value1, $key2 => $value2 ],
741 $cache->
getMulti( [ $key1, $key2, $key3 ], $curTTLs, [ $cKey1, $cKey2 ] ),
742 "Result array populated even with new check keys"
745 $this->assertGreaterThanOrEqual( $priorTime, $t1,
'Check key 1 generated on miss' );
747 $this->assertGreaterThanOrEqual( $priorTime, $t2,
'Check key 2 generated on miss' );
748 $this->assertEquals( 2, count( $curTTLs ),
"Current TTLs array set" );
749 $this->assertLessThanOrEqual( 0, $curTTLs[$key1],
'Key 1 has current TTL <= 0' );
750 $this->assertLessThanOrEqual( 0, $curTTLs[$key2],
'Key 2 has current TTL <= 0' );
755 [ $key1 => $value1, $key2 => $value2 ],
756 $cache->
getMulti( [ $key1, $key2, $key3 ], $curTTLs, [ $cKey1, $cKey2 ] ),
757 "Result array still populated even with new check keys"
759 $this->assertEquals( 2, count( $curTTLs ),
"Current TTLs still array set" );
760 $this->assertLessThan( 0, $curTTLs[$key1],
'Key 1 has negative current TTL' );
761 $this->assertLessThan( 0, $curTTLs[$key2],
'Key 2 has negative current TTL' );
780 foreach ( [ $checkAll, $check1, $check2 ] as $checkKey ) {
789 $result =
$cache->
getMulti( [
'key1',
'key2',
'key3' ], $curTTLs, [
796 [
'key1' => $value1,
'key2' => $value2 ],
800 $this->assertGreaterThanOrEqual( 9.5, $curTTLs[
'key1'],
'Initial ttls' );
801 $this->assertLessThanOrEqual( 10.5, $curTTLs[
'key1'],
'Initial ttls' );
802 $this->assertGreaterThanOrEqual( 9.5, $curTTLs[
'key2'],
'Initial ttls' );
803 $this->assertLessThanOrEqual( 10.5, $curTTLs[
'key2'],
'Initial ttls' );
808 $result =
$cache->
getMulti( [
'key1',
'key2',
'key3' ], $curTTLs, [
815 [
'key1' => $value1,
'key2' => $value2 ],
817 'key1 expired by check1, but value still provided'
819 $this->assertLessThan( 0, $curTTLs[
'key1'],
'key1 TTL expired' );
820 $this->assertGreaterThan( 0, $curTTLs[
'key2'],
'key2 still valid' );
825 $result =
$cache->
getMulti( [
'key1',
'key2',
'key3' ], $curTTLs, [
832 [
'key1' => $value1,
'key2' => $value2 ],
834 'All keys expired by checkAll, but value still provided'
836 $this->assertLessThan( 0, $curTTLs[
'key1'],
'key1 expired by checkAll' );
837 $this->assertLessThan( 0, $curTTLs[
'key2'],
'key2 expired by checkAll' );
924 $func =
function ( $old, &$ttl ) use ( &$wasSet,
$value ) {
932 $this->assertEquals(
$value, $v,
"Value returned" );
933 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
935 $this->assertEquals( 1, $wasSet,
"Value not regenerated" );
938 $verOpts = [
'version' => $extOpts[
'version'] + 1 ];
942 $this->assertEquals(
$value, $v,
"Value returned" );
943 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
947 $this->assertEquals(
$value, $v,
"Value returned" );
948 $this->assertEquals( 0, $wasSet,
"Value not regenerated" );
953 $this->assertEquals( 0, $wasSet,
"Value not regenerated" );
958 $this->assertEquals(
$value, $v,
"Value returned" );
959 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
963 $verOpts = [
'version' => $extOpts[
'version'] + 1 ];
965 $this->assertEquals(
$value, $v,
"Value returned" );
966 $this->assertEquals( 1, $wasSet,
"Value regenerated" );
985 $priorTime = microtime(
true );
987 $t0 = $this->
cache->getCheckKeyTime( $key );
988 $this->assertGreaterThanOrEqual( $priorTime, $t0,
'Check key auto-created' );
990 $priorTime = microtime(
true );
992 $this->
cache->touchCheckKey( $key );
993 $t1 = $this->
cache->getCheckKeyTime( $key );
994 $this->assertGreaterThanOrEqual( $priorTime, $t1,
'Check key created' );
996 $t2 = $this->
cache->getCheckKeyTime( $key );
997 $this->assertEquals( $t1, $t2,
'Check key time did not change' );
1000 $this->
cache->touchCheckKey( $key );
1001 $t3 = $this->
cache->getCheckKeyTime( $key );
1002 $this->assertGreaterThan( $t2, $t3,
'Check key time increased' );
1004 $t4 = $this->
cache->getCheckKeyTime( $key );
1005 $this->assertEquals( $t3, $t4,
'Check key time did not change' );
1008 $this->
cache->resetCheckKey( $key );
1009 $t5 = $this->
cache->getCheckKeyTime( $key );
1010 $this->assertGreaterThan( $t4, $t5,
'Check key time increased' );
1012 $t6 = $this->
cache->getCheckKeyTime( $key );
1013 $this->assertEquals( $t5, $t6,
'Check key time did not change' );
1026 $this->internalCache->set(
1027 WANObjectCache::TIME_KEY_PREFIX . $tKey2,
1028 WANObjectCache::PURGE_VAL_PREFIX . ( microtime(
true ) - 3 )
1030 $this->internalCache->set(
1031 WANObjectCache::TIME_KEY_PREFIX . $tKey2,
1032 WANObjectCache::PURGE_VAL_PREFIX . ( microtime(
true ) - 5 )
1034 $this->internalCache->set(
1035 WANObjectCache::TIME_KEY_PREFIX . $tKey1,
1036 WANObjectCache::PURGE_VAL_PREFIX . ( microtime(
true ) - 30 )
1041 $v = $this->
cache->get( $key, $curTTL, [ $tKey1, $tKey2 ] );
1042 $this->assertEquals(
$value, $v,
"Value matches" );
1043 $this->assertLessThan( -4.9, $curTTL,
"Correct CTL" );
1044 $this->assertGreaterThan( -5.1, $curTTL,
"Correct CTL" );
1058 $knownPurge = time() - 60;
1059 $goodTime = microtime(
true ) - 5;
1060 $badTime = microtime(
true ) - 300;
1062 $this->internalCache->set(
1063 WANObjectCache::VALUE_KEY_PREFIX . $vKey1,
1065 WANObjectCache::FLD_VERSION => WANObjectCache::VERSION,
1066 WANObjectCache::FLD_VALUE =>
$value,
1067 WANObjectCache::FLD_TTL => 3600,
1068 WANObjectCache::FLD_TIME => $goodTime
1071 $this->internalCache->set(
1072 WANObjectCache::VALUE_KEY_PREFIX . $vKey2,
1074 WANObjectCache::FLD_VERSION => WANObjectCache::VERSION,
1075 WANObjectCache::FLD_VALUE =>
$value,
1076 WANObjectCache::FLD_TTL => 3600,
1077 WANObjectCache::FLD_TIME => $badTime
1080 $this->internalCache->set(
1081 WANObjectCache::TIME_KEY_PREFIX . $tKey1,
1082 WANObjectCache::PURGE_VAL_PREFIX . $goodTime
1084 $this->internalCache->set(
1085 WANObjectCache::TIME_KEY_PREFIX . $tKey2,
1086 WANObjectCache::PURGE_VAL_PREFIX . $badTime
1089 $this->assertEquals(
$value, $this->
cache->get( $vKey1 ) );
1090 $this->assertEquals(
$value, $this->
cache->get( $vKey2 ) );
1091 $this->
cache->reap( $vKey1, $knownPurge, $bad1 );
1092 $this->
cache->reap( $vKey2, $knownPurge, $bad2 );
1094 $this->assertFalse( $bad1 );
1095 $this->assertTrue( $bad2 );
1097 $this->
cache->reapCheckKey( $tKey1, $knownPurge, $tBad1 );
1098 $this->
cache->reapCheckKey( $tKey2, $knownPurge, $tBad2 );
1099 $this->assertFalse( $tBad1 );
1100 $this->assertTrue( $tBad2 );
1172 $mtime = $ago ? time() - $ago : $ago;
1174 $ttl = $this->
cache->adaptiveTTL( $mtime, $maxTTL, $minTTL, $factor );
1176 $this->assertGreaterThanOrEqual( $adaptiveTTL - $margin, $ttl );
1177 $this->assertLessThanOrEqual( $adaptiveTTL + $margin, $ttl );
1179 $ttl = $this->
cache->adaptiveTTL( (
string)$mtime, $maxTTL, $minTTL, $factor );
1181 $this->assertGreaterThanOrEqual( $adaptiveTTL - $margin, $ttl );
1182 $this->assertLessThanOrEqual( $adaptiveTTL + $margin, $ttl );