Flintstone - Documentation

View Generated Docs

Loading a database

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

Options can be the following:

Option Description Default Value

dir

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

ext

The database file extension to use

.dat

gzip

Use gzip to compress the database

false

cache

Whether to cache get() results for faster data retrieval

true

formatter

The formatter class used to encode/decode data

null

swap_memory_limit

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

2097152

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.

flush()

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

getKeys()

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

getAll()

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:

<?php
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.