write() public method

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`.
return boolean `true` on successful write, `false` otherwise.
Esempio n. 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);
 }
Esempio n. 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);
 }