Extends
lithium\core\Object
Write value(s) to the cache
Parameters
- string $key The key to uniquely identify the cached item
- mixed $value The value to be cached
- null|string $expiry A strtotime() compatible cache time. If no expiry time is set, then the default cache expiration time set with the cache configuration will be used.
Returns
closure Function returning boolean `true` on successful write, `false` otherwise.Source
public function write($key, $value = null, $expiry = null) {
$connection =& $this->connection;
$expiry = ($expiry) ?: $this->_config['expiry'];
$_self =& $this;
return function($self, $params) use (&$_self, &$connection, $expiry) {
if (is_array($params['key'])) {
$expiry = $params['data'];
if ($connection->mset($params['key'])) {
$ttl = array();
if ($expiry) {
foreach ($params['key'] as $k => $v) {
$ttl[$k] = $_self->invokeMethod('_ttl', array($k, $expiry));
}
}
return $ttl;
}
}
if ($result = $connection->set($params['key'], $params['data'])) {
if ($expiry) {
return $_self->invokeMethod('_ttl', array($params['key'], $expiry));
}
return $result;
}
};
}