Cache to a MySQL database using the mysqli PHP extension.
You must pass a mysqli
connection object to the constructor.
<?php
use Desarrolla2\Cache\Mysqli as MysqliCache;
$db = new mysqli('localhost');
$cache = new MysqliCache($db);
name | type | default | |
---|---|---|---|
initialize | bool | true | Enable auto-initialize |
ttl | int | null | Maximum time to live in seconds |
prefix | string | "" | Key prefix |
If initialize
is enabled, the cache implementation will automatically create
a scheduled event.
DELIMITER ;;
CREATE TABLE IF NOT EXISTS `cache` (`key` VARCHAR(255), `value` TEXT, `ttl` INT UNSIGNED, PRIMARY KEY (`key`));;
CREATE EVENT `apply_ttl_cache` ON SCHEDULE 1 HOUR
DO BEGIN
DELETE FROM `cache` WHERE `ttl` < NOW();
END;;
In production it's better to disable auto-initialization and create the event
explicitly when setting up the database. This prevents a CREATE TABLE
and
CREATE EVENT
query on each request.
By default the SerializePacker
is used.