CacheTest::testOutputLibmemcachedCache PHP Method

testOutputLibmemcachedCache() public method

    public function testOutputLibmemcachedCache()
    {
        $memcache = $this->_prepareLibmemcached();
        if (!$memcache) {
            return false;
        }
        $memcache->delete('test-output');
        $time = date('H:i:s');
        $frontCache = new Phalcon\Cache\Frontend\Output(array('lifetime' => 2));
        $cache = new Phalcon\Cache\Backend\Libmemcached($frontCache);
        ob_start();
        //First time cache
        $content = $cache->start('test-output');
        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->assertEquals($time, $memcache->get('test-output'));
        //Expect same cache
        $content = $cache->start('test-output');
        if ($content === null) {
            $this->assertTrue(false);
        }
        $this->assertEquals($time, $obContent);
        //Refresh cache
        sleep(3);
        $time2 = date('H:i:s');
        ob_start();
        $content = $cache->start('test-output');
        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);
        $this->assertEquals($time2, $memcache->get('test-output'));
        //Check if exists
        $this->assertTrue($cache->exists('test-output'));
        //Delete entry from cache
        $this->assertTrue($cache->delete('test-output'));
        $memcache->quit();
    }