Can handle single- and multi-key writes.
This method has two valid syntaxes depending on if you're storing
data using a single key or multiple keys as outlined below.
To write data to a single-key use the following syntax.
Cache::write('default', 'foo', 'bar', '+1 minute');
For multi-key writes the $data parameter's role becomes
the one of the $expiry parameter.
Cache::write('default', array('foo' => 'bar', ... ), '+1 minute');
These two calls are synonymical and demonstrate the two
possible ways to specify the expiration time.
Cache::write('default', 'foo', 'bar', '+1 minute');
Cache::write('default', 'foo', 'bar', 60);
public static write ( string $name, mixed $key, mixed $data = null, string | integer $expiry = null, array $options = [] ) : boolean | ||
$name | string | Configuration to be used for writing. |
$key | mixed | Key to uniquely identify the cache entry or an array of key/value pairs for multi-key writes mapping cache keys to the data to be cached. |
$data | mixed | Data to be cached. |
$expiry | string | integer | A `strtotime()` compatible cache time. Alternatively an integer denoting the seconds until the item expires (TTL). If no expiry time is set, then the default cache expiration time set with the cache adapter configuration will be used. To persist an item use `Cache::PERSIST`. |
$options | array | Options for the method and strategies. - `'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 | boolean | `true` on successful cache write, `false` otherwise. When writing multiple items and an error occurs writing any of the items the whole operation fails and this method will return `false`. |