SQL Adapter
Use a database table for your cache. I don’t imagine this would be very efficient. The table should have columns for id, content, and expiry.
CREATE TABLE vespula_cache ('id VARCHAR(64), content BLOB, expiry INTEGER NULL');
NOTE: The order of the parameters on the Sql Adpater constructor have changed. The table name is now the second parameter.
<?php
include 'vendor/autoload.php';
use PDO;
use Vespula\Cache\Adapter\Sql as SqlCache;
$pdo = new PDO("mysql:host=localhost;dbname=mydb;charset=utf8", 'username', '******');
$table = 'vespula_cache';
// The TTL can be an integer(seconds), a DateInterval, or null (no expiry).
$default_ttl = 3600;
$adapter = new SqlCache($pdo, $table, $default_ttl);
/ Set a value by key with key-specific ttl (optional)
$adapter->set('cat', 'meow', 1800);
// returns 'meow' if still in cache
$value = $adapter->get('cat');
// returns 'meow' if still in cache, or 'some default' if not.
$value = $adapter->get('cat', 'some default');
// Delete a value by key
$adapter->delete('cat');
// Check for presence in the cache
$is_cached = $adapter->has($key);
// Delete all entries in the cache
$adapter->clear();
// Update the expiry on an item
$ttl = 1800;
$key = 'cat';
$adapter->touch($key, $ttl);
// Delete multiples
$keys = [
'foo',
'bar'
];
$adapter->deleteMultiple($keys);