public function testFindExpired()
 {
     $capabilities = $this->_storage->getCapabilities();
     if (!$capabilities->getIterable()) {
         $this->markTestSkipped("Find isn't supported by this adapter");
     }
     $this->_options->setTtl($capabilities->getTtlPrecision());
     $this->assertTrue($this->_storage->setItem('key1', 'value1'));
     $this->assertTrue($this->_storage->setItem('key2', 'value2'));
     // wait until first 2 items expired
     usleep($capabilities->getTtlPrecision() * 2000000);
     $this->assertTrue($this->_storage->setItem('key3', 'value3'));
     $this->assertTrue($this->_storage->setItem('key4', 'value4'));
     $this->assertTrue($this->_storage->find(Adapter::MATCH_EXPIRED));
     if ($capabilities->getExpiredRead() && !$capabilities->getUseRequestTime()) {
         $expectedItems = array('key1' => 'value1', 'key2' => 'value2');
     } else {
         $expectedItems = array();
     }
     $actualItems = array();
     while (($item = $this->_storage->fetch()) !== false) {
         // check $item
         $this->assertArrayHasKey('key', $item);
         $this->assertArrayHasKey('value', $item);
         $this->assertEquals(2, count($item));
         $actualItems[$item['key']] = $item['value'];
     }
     ksort($actualItems);
     $this->assertEquals($expectedItems, $actualItems);
 }
Beispiel #2
0
 /**
  * Returns the page item cache.
  *
  * @return array
  */
 public function getPageItemCache()
 {
     $data = array();
     if ($this->_cacheEnabled()) {
         $cacheIds = self::$_cache->find(CacheAdapter::MATCH_TAGS_OR, array('tags' => array($this->_getCacheInternalId())));
         $cacheIds = array();
         while (($item = self::$_cache->fetch()) !== false) {
             $cacheIds[] = $item['key'];
         }
         foreach ($cacheIds as $id) {
             if (preg_match('|' . self::CACHE_TAG_PREFIX . "(\\d+)_.*|", $id, $page)) {
                 $data[$page[1]] = self::$_cache->getItem($this->_getCacheId($page[1]));
             }
         }
     }
     return $data;
 }
Beispiel #3
0
 public function testTagsAreUsedWhenCaching()
 {
     $capabilities = $this->_storage->getCapabilities();
     if (!$capabilities->getTagging()) {
         $this->markTestSkipped("Tags are not supported by this adapter");
     }
     // Ensure we don't have expired items in the cache for this test
     $this->_options->setTtl(60);
     $this->_storage->setItem('someitem', 'somevalue', array('tags' => array('foo')));
     $this->assertTrue($this->_storage->find(Cache\Storage\Adapter::MATCH_TAGS_OR, array('tags' => array('foo'))));
     $actualItems = array();
     while (($item = $this->_storage->fetch()) !== false) {
         // check $item
         $this->assertArrayHasKey('key', $item);
         $this->assertArrayHasKey('value', $item);
         $actualItems[$item['key']] = $item['value'];
     }
     $this->assertEquals(1, count($actualItems));
     $this->assertArrayHasKey('someitem', $actualItems);
     $this->assertEquals('somevalue', $actualItems['someitem']);
 }