Beispiel #1
0
 * disk cache instance
 */
$disk = new DALMP\Cache(new DALMP\Cache\Disk());
/**
 * database instance
 */
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
$sql = 'SELECT * FROM Country LIMIT 2';
/**
 * Cache for 5 minutes with key: mykey using memcache cache
 */
$db->useCache($memcache);
$rs = $db->CacheGetAll(300, $sql, 'mykey');
$timer->setMark('memcache');
echo count($rs), PHP_EOL;
$rs = $db->CacheGetAll(300, $sql, 'mykey');
$timer->setMark('memcache2');
echo count($rs), PHP_EOL;
/**
 * Cache for 5 minutes with key: mykey using redis cache
 */
$db->debug();
$db->useCache($redis);
$rs = $db->CacheGetAll(300, $sql, 'mykey');
$timer->setMark('redis');
echo count($rs), PHP_EOL;
$rs = $db->CacheGetAll(300, $sql, 'mykey');
Beispiel #2
0
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_HOST') ?: '3306';
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
/**
 * use redis as cache engine
 */
$db->useCache(new DALMP\Cache(new DALMP\Cache\Redis('127.0.0.1', 6379)));
$db->FetchMode('ASSOC');
/**
 * Cache for 5 minutes, group A
 */
$rs = $db->CachePGetAll(300, 'SELECT * FROM Country WHERE Region = ?', 'Caribbean', 'group:A');
echo count($rs), PHP_EOL;
$timer->setMark('300');
/**
 * Cache for 1 day (86400 seconds), group B
 */
$rs = $db->CachePGetAll(86400, 'SELECT * FROM Country WHERE Continent = ?', 'Europe', 'group:B');
echo count($rs), PHP_EOL;
$timer->setMark('86400');
/**
 * Cache for 1 hour (default), group C
 */