public write ( array $keys, string | integer $expiry = null ) : boolean | ||
$keys | array | Key/value pairs with keys to uniquely identify the to-be-cached item. |
$expiry | string | integer | A `strtotime()` compatible cache time or TTL in seconds. To persist an item use `\lithium\storage\Cache::PERSIST`. |
return | boolean | `true` on successful write, `false` otherwise. |
public function write(array $keys, $expiry = null)
{
$expiry = $expiry || $expiry === Cache::PERSIST ? $expiry : $this->_config['expiry'];
if (!$expiry || $expiry === Cache::PERSIST) {
$ttl = 0;
} elseif (is_int($expiry)) {
$ttl = $expiry;
} else {
$ttl = strtotime($expiry) - time();
}
if ($this->_config['scope']) {
$keys = $this->_addScopePrefix($this->_config['scope'], $keys);
}
return apc_store($keys, null, $ttl) === array();
}
public function testWriteDefaultCacheTime() { $Apc = new Apc(array('expiry' => '+5 seconds')); $key = 'key'; $data = 'value'; $closure = $Apc->write($key, $data); $this->assertTrue(is_callable($closure)); $params = compact('key', 'data'); $result = $closure($Apc, $params, null); $expected = $data; $this->assertTrue($result); $result = apc_fetch($key); $this->assertEqual($expected, $result); $result = apc_delete($key); $this->assertTrue($result); }