public function testCacheIsStaleBySingle()
 {
     $data[] = ['colour' => 'red', 'size' => 'large', 'ID' => 388];
     $data[] = ['colour' => 'blue', 'size' => 'medium', 'ID' => 389];
     $data[] = ['colour' => 'green', 'size' => 'small', 'ID' => 390];
     $record = ['colour' => 'blue', 'size' => 'small', 'ID' => 390];
     $cacheFresh = \CacheEvaluator\Evaluate\SingleRecord::fromArray($data, $record)->addFieldToMatch('ID')->addFieldToCheck('colour')->addFieldToCheck('size')->evaluate();
     $this->assertEquals(true, $cacheFresh->isCacheStale());
 }
Ejemplo n.º 2
0
}
require __DIR__ . '/../vendor/autoload.php';
$data[] = ['colour' => 'red', 'size' => 'large', 'ID' => 388];
$data[] = ['colour' => 'blue', 'size' => 'medium', 'ID' => 389];
$data[] = ['colour' => 'green', 'size' => 'small', 'ID' => 390];
$record = ['colour' => 'green', 'size' => 'small', 'ID' => 390];
$cacheFresh = \CacheEvaluator\Evaluate\SingleRecord::fromArray($data, $record)->addFieldToMatch('ID')->addFieldToCheck('colour')->addFieldToCheck('size')->evaluate();
if ($cacheFresh->isCacheFresh()) {
    echo '<p>The cache is still fresh!</p>';
    var_dump($cacheFresh->getRecordChanged());
} else {
    echo '<p>The cache is now stale.</p>';
    var_dump($cacheFresh->getRecordChanged());
}
$record = ['colour' => 'blue', 'size' => 'small', 'ID' => 390];
$cacheFresh = \CacheEvaluator\Evaluate\SingleRecord::fromArray($data, $record)->addFieldToMatch('ID')->addFieldToCheck('colour')->addFieldToCheck('size')->evaluate();
if ($cacheFresh->isCacheFresh()) {
    echo '<p>The cache is still fresh!</p>';
    var_dump($cacheFresh->getRecordChanged());
} else {
    echo '<p>The cache is now stale.</p>';
    var_dump($cacheFresh->getRecordChanged());
}
$records = [['colour' => 'green', 'size' => 'small', 'ID' => 390], ['colour' => 'blue', 'size' => 'medium', 'ID' => 389]];
$cacheFresh = \CacheEvaluator\Evaluate\MultipleRecords::fromArray($data, $records)->addFieldToMatch('ID')->addFieldToCheck('colour')->addFieldToCheck('size')->evaluate();
if ($cacheFresh->isCacheFresh()) {
    echo '<p>The cache is still fresh!</p>';
    echo var_dump($cacheFresh->getRecordsDifferentInCache()) . '<br>';
    echo var_dump($cacheFresh->getRecordsSameInCache()) . '<br>';
} else {
    echo '<p>The cache is now stale.</p>';