write() public method

Write values to the cache. All items to be cached will receive an expiration time of $expiry.
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.
コード例 #1
0
ファイル: ApcTest.php プロジェクト: WarToaster/HangOn
 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);
 }
コード例 #2
0
ファイル: ApcTest.php プロジェクト: unionofrad/lithium
 public function testWriteWithScope()
 {
     $adapter = new Apc(array('scope' => 'primary'));
     $keys = array('key1' => 'test1');
     $expiry = '+1 minute';
     $adapter->write($keys, $expiry);
     $expected = 'test1';
     $result = apc_fetch('primary:key1');
     $this->assertEqual($expected, $result);
     $result = apc_fetch('key1');
     $this->assertFalse($result);
 }