lithium\storage\cache\adapter\File::read PHP Method

read() public method

Invalidates and cleans up expired items on-the-fly when found.
public read ( array $keys ) : array
$keys array Keys to uniquely identify the cached items.
return array Cached values keyed by cache keys on successful read, keys which could not be read will not be included in the results array.
    public function read(array $keys)
    {
        if ($this->_config['scope']) {
            $keys = $this->_addScopePrefix($this->_config['scope'], $keys, '_');
        }
        $results = array();
        foreach ($keys as $key) {
            if (!($item = $this->_read($key))) {
                continue;
            }
            if ($item['expiry'] < time() && $item['expiry'] != 0) {
                $this->_delete($key);
                continue;
            }
            $results[$key] = $item['value'];
        }
        if ($this->_config['scope']) {
            $results = $this->_removeScopePrefix($this->_config['scope'], $results, '_');
        }
        return $results;
    }

Usage Example

Example #1
0
 public function testIncrementWithScope()
 {
     $adapter = new File(array('scope' => 'primary'));
     $this->File->write(array('primary_key1' => 5));
     $this->File->write(array('key1' => 10));
     $expected = 6;
     $result = $adapter->increment('key1');
     $this->assertEqual($expected, $result);
     $expected = array('key1' => 6);
     $result = $adapter->read(array('key1'));
     $this->assertEqual($expected, $result);
 }