Flintstone - Documentation

View Generated Docs

Loading a database

$options = ['dir' => '/path/to/database/dir/'];
$users = new Flintstone('users', $options);

Options can be the following:

Option Description Default Value


The directory where the database files are stored (this should be somewhere that is not web accessible) e.g. /path/to/database/

current working directory


The database file extension to use



Use gzip to compress the database



Whether to cache get() results for faster data retrieval



The formatter class used to encode/decode data



The amount of memory to use before writing to a temporary file


Flintstone has the following public methods:

Method Description

get(string $key)

Retrieve data for the key name. Returns false if it does not exist.

set(string $key, mixed $data)

Set data for the key name. Data can be a string, integer, float or array. Will throw an exception if fails to set.

delete(string $key)

Delete the key name. Will throw an exception if fails to delete.


Empty the database. Will throw an exception if fails to flush.


Returns an array of all of the keys in the database.


Returns all data in the database.

Changing the formatter

By default Flintstone will encode/decode data using PHP's serialize functions, however you can override this with your own class if you prefer.

Just make sure it implements Flintstone\Formatter\FormatterInterface and then you can provide it as the formatter option.

If you wish to use JSON as the formatter, Flintstone already ships with this as per the example below:

require 'vendor/autoload.php';

use Flintstone\Flintstone;
use Flintstone\Formatter\JsonFormatter;

$users = new Flintstone('users', [
	'dir' => __DIR__,
	'formatter' => new JsonFormatter()

Changing the cache

To speed up data retrieval Flintstone can store the results of get() in a cache store. By default this uses a simple array that only persist's for as long as the Flintstone object exists.

If you want to use your own cache store (such as Memcached) you can pass a class as the cache option. Just make sure it implements Flintstone\Cache\CacheInterface.