public function testCacheIsStaleByMultiple() { $data[] = ['colour' => 'red', 'size' => 'large', 'ID' => 388]; $data[] = ['colour' => 'blue', 'size' => 'medium', 'ID' => 389]; $data[] = ['colour' => 'green', 'size' => 'small', 'ID' => 390]; $records = [['colour' => 'blue', 'size' => 'small', 'ID' => 390], ['colour' => 'blue', 'size' => 'medium', 'ID' => 389]]; $cacheFresh = \CacheEvaluator\Evaluate\MultipleRecords::fromArray($data, $records)->addFieldToMatch('ID')->addFieldToCheck('colour')->addFieldToCheck('size')->evaluate(); $this->assertEquals(true, $cacheFresh->isCacheStale()); }
$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>'; echo var_dump($cacheFresh->getRecordsDifferentInCache()) . '<br>'; echo var_dump($cacheFresh->getRecordsSameInCache()) . '<br>'; } $records = [['colour' => 'green', 'size' => 'small', 'ID' => 390], ['colour' => 'blue', 'size' => 'large', '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>'; echo var_dump($cacheFresh->getRecordsDifferentInCache()) . '<br>'; echo var_dump($cacheFresh->getRecordsSameInCache()) . '<br>'; }