Flintstone\Flintstone::flush PHP Method

flush() public method

Flush the database.
public flush ( )
    public function flush()
    {
        $filePointer = $this->getDatabase()->openFile(Database::FILE_WRITE);
        $this->getDatabase()->closeFile($filePointer);
        // Flush the cache
        if ($cache = $this->getConfig()->getCache()) {
            $cache->flush();
        }
    }

Usage Example

Beispiel #1
0
 protected function runOperationsTests($config)
 {
     $db = new Flintstone('test', $config);
     $arr = array('foo' => "new\nline");
     $this->assertFalse($db->get('foo'));
     $db->set('foo', 1);
     $db->set('name', 'john');
     $db->set('arr', $arr);
     $this->assertEquals(1, $db->get('foo'));
     $this->assertEquals('john', $db->get('name'));
     $this->assertEquals($arr, $db->get('arr'));
     $db->set('foo', 2);
     $this->assertEquals(2, $db->get('foo'));
     $this->assertEquals('john', $db->get('name'));
     $this->assertEquals($arr, $db->get('arr'));
     $db->delete('name');
     $this->assertFalse($db->get('name'));
     $this->assertEquals($arr, $db->get('arr'));
     $keys = $db->getKeys();
     $this->assertEquals(2, count($keys));
     $this->assertEquals('foo', $keys[0]);
     $this->assertEquals('arr', $keys[1]);
     $data = $db->getAll();
     $this->assertEquals(2, count($data));
     $this->assertEquals(2, $data['foo']);
     $this->assertEquals($arr, $data['arr']);
     $db->flush();
     $this->assertFalse($db->get('foo'));
     $this->assertFalse($db->get('arr'));
     $this->assertEquals(0, count($db->getKeys()));
     $this->assertEquals(0, count($db->getAll()));
     unlink($db->getDatabase()->getPath());
 }