for ($i = 0;
$i <
$max_rows;
$i++
) { // Ensure that each cache item created happens in a different millisecond,
// by waiting 1 ms (1000 microseconds). The garbage collection might
// otherwise keep less than exactly 100 records (which is acceptable for
// real-world cases, but not for this test).
usleep(1000
);
$backend->
set("test
$i",
$i);
} $this->
assertSame($max_rows,
$this->
getNumRows());
// Garbage collection has no effect.
$backend->
garbageCollection();
$this->
assertSame($max_rows,
$this->
getNumRows());
// Go one row beyond the limit.
$backend->
set('test' .
($max_rows + 1
),
$max_rows + 1
);
$this->
assertSame($max_rows + 1,
$this->
getNumRows());
// Garbage collection removes one row: the oldest.
$backend->
garbageCollection();
$this->
assertSame($max_rows,
$this->
getNumRows());
$this->
assertFalse($backend->
get('test0'
));
}