Can handle single- and multi-key reads.
Read-through caching can be used by passing expiry and the to-be-cached value
in the write option. Following three ways to achieve this.
Cache::read('default', 'foo', array(
'write' => array('+5 days' => 'bar')
)); // returns 'bar'
Cache::read('default', 'foo', array(
'write' => array('+5 days' => function() { return 'bar'; })
));
Cache::read('default', 'foo', array(
'write' => function() { return array('+5 days' => 'bar'); }
));
public static read ( string $name, mixed $key, array $options = [] ) : mixed | ||
$name | string | Configuration to be used for reading. |
$key | mixed | Key to uniquely identify the cache entry or an array of keys for multikey-reads. |
$options | array | Options for the method and strategies. - `'write'`: Allows for read-through caching see description for usage. - `'strategies'` _boolean_: Indicates if strategies should be used, defaults to `true`. - `'conditions'` _mixed_: A function or item that must return or evaluate to `true` in order to continue write operation. |
return | mixed | For single-key reads will return the result if the cache key has been found otherwise returns `null`. When reading multiple keys a results array is returned mapping keys to retrieved values. Keys where the value couldn't successfully been read will not be contained in the results array. |