lithium\storage\cache\adapter\Memcache::write PHP Method

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.
    public function write(array $keys, $expiry = null)
    {
        $expiry = $expiry || $expiry === Cache::PERSIST ? $expiry : $this->_config['expiry'];
        if (!$expiry || $expiry === Cache::PERSIST) {
            $expires = 0;
        } elseif (is_int($expiry)) {
            $expires = $expiry + time();
        } else {
            $expires = strtotime($expiry);
        }
        if (count($keys) > 1) {
            return $this->connection->setMulti($keys, $expires);
        }
        return $this->connection->set(key($keys), current($keys), $expires);
    }

Usage Example

Exemplo 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);
 }
All Usage Examples Of lithium\storage\cache\adapter\Memcache::write