drinky08/cache-evaluator

PHP class to determine whether or not a cache is fresh.

2.0.2 2016-01-18 12:35 UTC

This package is not auto-updated.

Last update: 2020-10-28 06:15:24 UTC


README

PHP class to determine whether or not a cache is fresh.

Usage

$cacheFresh = \CacheEvaluator\Evaluate\SingleRecord::fromArray((array) $data, (array) $record)
  ->addFieldToMatch((string) $field1)
  ->addFieldToCheck((string) $field2)
  ->evaluate()
  ->isCacheFresh();
$cacheFresh = \CacheEvaluator\Evaluate\MultipleRecords::fromArray((array) $data, (array) $records)
  ->addFieldToMatch((string) $field1)
  ->addFieldToCheck((string) $field2)
  ->evaluate()
  ->isCacheFresh();
$recordsDifferentInCache = \CacheEvaluator\Evaluate\MultipleRecords::fromArray((array) $data, (array) $records)
  ->addFieldToMatch((string) $field1)
  ->addFieldToCheck((string) $field2)
  ->evaluate()
  ->getRecordsDifferentInCache();

CacheEvaluator expects the following format for inputs:

  • Existing cache data is expected in the folowing format: [0 => ['col1' => 'blah', 'col2' => 'blah'], 1 =>['col1' => 'blah', 'col2' => 'blah']]
  • Existing record is expected in the following format for SingleRecord: ['col1' => 'blah', 'col2' => 'blah']
  • Existing records is expected in the following format for MultipleRecords: [['col1' => 'blah', 'col2' => 'blah'],['col1' => 'foo', 'col2' => 'bah']]
  • Fields to match and fields to check is expected in the following format: ['col1', 'col2']