write() public méthode

Note that this is not an atomic operation when using multiple keys.
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`.
Résultat boolean `true` on successful write, `false` otherwise.
Exemple #1
0
 public function testWriteDefaultCacheExpiry()
 {
     $XCache = new XCache(array('expiry' => '+5 seconds'));
     $key = 'default_key';
     $data = 'value';
     $time = strtotime('+5 seconds');
     $closure = $XCache->write($key, $data);
     $this->assertTrue(is_callable($closure));
     $params = compact('key', 'data');
     $result = $closure($XCache, $params, null);
     $expected = $data;
     $this->assertEqual($expected, $result);
     $result = xcache_get($key);
     $this->assertEqual($expected, $result);
     $result = xcache_unset($key);
     $this->assertTrue($result);
 }
Exemple #2
0
 public function testWriteWithScope()
 {
     $adapter = new XCache(array('scope' => 'primary'));
     $keys = array('key1' => 'test1');
     $expiry = '+1 minute';
     $adapter->write($keys, $expiry);
     $expected = 'test1';
     $result = xcache_get('primary:key1');
     $this->assertEqual($expected, $result);
     $result = xcache_get('key1');
     $this->assertNull($result);
 }