Example #1
0
 /**
  * Returns the page item cache.
  *
  * @return array
  */
 public function getPageItemCache()
 {
     $data = array();
     if ($this->cacheEnabled()) {
         $prefixLength = strlen(self::CACHE_TAG_PREFIX);
         $cacheIterator = static::$cache->getIterator();
         $cacheIterator->setMode(CacheIterator::CURRENT_AS_VALUE);
         foreach ($cacheIterator as $key => $value) {
             if (substr($key, 0, $prefixLength) == self::CACHE_TAG_PREFIX) {
                 $data[(int) substr($key, $prefixLength)] = $value;
             }
         }
     }
     return $data;
 }
Example #2
0
 public function testIterator()
 {
     if (!$this->_storage instanceof IterableInterface) {
         $this->markTestSkipped("Storage doesn't implement IterableInterface");
     }
     $items = array('key1' => 'value1', 'key2' => 'value2');
     $this->assertSame(array(), $this->_storage->setItems($items));
     // check iterator aggregate
     $iterator = $this->_storage->getIterator();
     $this->assertInstanceOf('Zend\\Cache\\Storage\\IteratorInterface', $iterator);
     $this->assertSame(IteratorInterface::CURRENT_AS_KEY, $iterator->getMode());
     // check mode CURRENT_AS_KEY
     $iterator = $this->_storage->getIterator();
     $iterator->setMode(IteratorInterface::CURRENT_AS_KEY);
     $keys = iterator_to_array($iterator, false);
     sort($keys);
     $this->assertSame(array_keys($items), $keys);
     // check mode CURRENT_AS_VALUE
     $iterator = $this->_storage->getIterator();
     $iterator->setMode(IteratorInterface::CURRENT_AS_VALUE);
     $result = iterator_to_array($iterator, true);
     ksort($result);
     $this->assertSame($items, $result);
 }