Exemple #1
0
 public function ytestOutputFileCache()
 {
     for ($i = 0; $i < 2; $i++) {
         $time = date('H:i:s');
         $frontCache = new Phalcon\Cache\Frontend\Output(array('lifetime' => 2));
         $cache = new Phalcon\Cache\Backend\File($frontCache, array('cacheDir' => 'unit-tests/cache/', 'prefix' => 'unit'));
         // on the second run set useSafeKey to true to test the compatibility toggle
         if ($i == 1) {
             $cache->useSafeKey(true);
         }
         $this->assertFalse($cache->isStarted());
         ob_start();
         //First time cache
         $content = $cache->start('testoutput');
         $this->assertTrue($cache->isStarted());
         if ($content !== null) {
             $this->assertTrue(false);
         }
         echo $time;
         $cache->save(null, null, null, true);
         $obContent = ob_get_contents();
         ob_end_clean();
         $this->assertEquals($time, $obContent);
         $this->assertTrue(file_exists('unit-tests/cache/unit' . $cache->getKey('testoutput')));
         //Same cache
         $content = $cache->start('testoutput');
         $this->assertTrue($cache->isStarted());
         if ($content === null) {
             $this->assertTrue(false);
         }
         $this->assertEquals($time, $obContent);
         //Refresh cache
         sleep(3);
         $time2 = date('H:i:s');
         ob_start();
         $content = $cache->start('testoutput');
         $this->assertTrue($cache->isStarted());
         if ($content !== null) {
             $this->assertTrue(false);
         }
         echo $time2;
         $cache->save(null, null, null, true);
         $obContent2 = ob_get_contents();
         ob_end_clean();
         $this->assertNotEquals($time, $obContent2);
         $this->assertEquals($time2, $obContent2);
         //Check keys
         $keys = $cache->queryKeys();
         $this->assertEquals($keys, array(0 => 'unit' . $cache->getKey('testoutput')));
         $this->assertTrue($cache->exists('testoutput'));
         //Delete cache
         $this->assertTrue($cache->delete('testoutput'));
     }
 }
Exemple #2
0
 public function testOutputFileCache()
 {
     $time = date('H:i:s');
     $frontCache = new Phalcon\Cache\Frontend\Output(array('lifetime' => 2));
     $cache = new Phalcon\Cache\Backend\File($frontCache, array('cacheDir' => 'unit-tests/cache/', 'prefix' => 'unit'));
     $this->assertFalse($cache->isStarted());
     ob_start();
     //First time cache
     $content = $cache->start('testoutput');
     $this->assertTrue($cache->isStarted());
     if ($content !== null) {
         $this->assertTrue(false);
     }
     echo $time;
     $cache->save(null, null, null, true);
     $obContent = ob_get_contents();
     ob_end_clean();
     $this->assertEquals($time, $obContent);
     $this->assertTrue(file_exists('unit-tests/cache/unittestoutput'));
     //Same cache
     $content = $cache->start('testoutput');
     $this->assertTrue($cache->isStarted());
     if ($content === null) {
         $this->assertTrue(false);
     }
     $this->assertEquals($time, $obContent);
     //Refresh cache
     sleep(3);
     $time2 = date('H:i:s');
     ob_start();
     $content = $cache->start('testoutput');
     $this->assertTrue($cache->isStarted());
     if ($content !== null) {
         $this->assertTrue(false);
     }
     echo $time2;
     $cache->save(null, null, null, true);
     $obContent2 = ob_get_contents();
     ob_end_clean();
     $this->assertNotEquals($time, $obContent2);
     $this->assertEquals($time2, $obContent2);
     //Check keys
     $keys = $cache->queryKeys();
     $this->assertEquals($keys, array(0 => 'unittestoutput'));
     // $cache->exists('testoutput') is not always true because Travis CI could be slow sometimes
     //Exists?
     if ($cache->exists('testoutput')) {
         $this->assertTrue($cache->exists('testoutput'));
         //Delete cache
         $this->assertTrue($cache->delete('testoutput'));
     }
 }