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`. |
리턴 | boolean | `true` on successful write, `false` otherwise. |
public function testWriteWithScope() { $adapter = new Redis(array('scope' => 'primary')); $keys = array('key1' => 'test1'); $expiry = '+1 minute'; $adapter->write($keys, $expiry); $expected = 'test1'; $result = $this->_redis->get('primary:key1'); $this->assertEqual($expected, $result); $result = $this->_redis->get('key1'); $this->assertFalse($result); }
public function testWriteNoCacheExpiry() { $redis = new Redis(array('expiry' => null)); $key = 'default_key'; $data = 'value'; $redis->write($key, $data)->__invoke(null, compact('key', 'data'), null); $this->assertEqual($data, $this->_redis->get($key)); $this->assertTrue($this->_redis->delete($key)); }
public function testWriteDefaultCacheExpiry() { $Redis = new Redis(array('expiry' => '+5 seconds')); $key = 'default_key'; $data = 'value'; $time = strtotime('+5 seconds'); $closure = $Redis->write($key, $data); $this->assertTrue(is_callable($closure)); $params = compact('key', 'data'); $result = $closure($Redis, $params, null); $expected = $data; $this->assertEqual($expected, $result); $result = $this->_Redis->get($key); $this->assertEqual($expected, $result); $result = $this->_Redis->ttl($key); $this->assertEqual($time - time(), $result); $result = $this->_Redis->delete($key); $this->assertTrue($result); }