write() 공개 메소드

Expiration is always based off the current unix time in order to gurantee we never exceed the TTL limit of 30 days when specifying the TTL directly.
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`.
리턴 boolean `true` on successful write, `false` otherwise.
예제 #1
0
 public function testWriteDefaultCacheExpiry()
 {
     $memcache = new Memcache(array('expiry' => '+5 seconds'));
     $key = 'default_key';
     $data = 'value';
     $closure = $memcache->write($key, $data);
     $this->assertTrue(is_callable($closure));
     $params = compact('key', 'data');
     $result = $closure($memcache, $params);
     $expected = $data;
     $this->assertEqual($expected, $result);
     $result = $this->_conn->get($key);
     $this->assertEqual($expected, $result);
     $result = $this->_conn->delete($key);
     $this->assertTrue($result);
 }
예제 #2
0
 public function testWriteWithScope()
 {
     $adapter = new Memcache(array('scope' => 'primary'));
     $keys = array('key1' => 'test1');
     $expiry = '+1 minute';
     $adapter->write($keys, $expiry);
     $expected = 'test1';
     $result = $this->_conn->get('primary:key1');
     $this->assertEqual($expected, $result);
     $result = $this->_conn->get('key1');
     $this->assertFalse($result);
 }