1<?php 2 3require_once '../../MPLT.php'; 4$timer = new MPLT(); 5require_once '../../src/dalmp.php'; 6# ------------------------------------------------------------------------------ 7 8/** 9 * memcache cache instance 10 */ 11$memcache = new DALMP\Cache(new DALMP\Cache\Memcache()); 12 13/** 14 * redis cache instance 15 */ 16$redis = new DALMP\Cache(new DALMP\Cache\Redis()); 17 18/** 19 * disk cache instance 20 */ 21$disk = new DALMP\Cache(new DALMP\Cache\Disk()); 22 23/** 24 * database instance 25 */ 26$user = getenv('MYSQL_USER') ?: 'root'; 27$password = getenv('MYSQL_PASS') ?: ''; 28$host = getenv('MYSQL_HOST') ?: '127.0.0.1'; 29$port = getenv('MYSQL_PORT') ?: '3306'; 30$db = new DALMP\Database("utf8://$user:$password@$host:$port/dalmp"); 31 32$sql = 'SELECT * FROM Country LIMIT 2'; 33 34/** 35 * Cache for 5 minutes with key: mykey using memcache cache 36 */ 37$db->useCache($memcache); 38$rs = $db->CacheGetAll(300, $sql, 'mykey'); 39$timer->setMark('memcache'); 40echo count($rs),PHP_EOL; 41$rs = $db->CacheGetAll(300, $sql, 'mykey'); 42$timer->setMark('memcache2'); 43echo count($rs),PHP_EOL; 44 45/** 46 * Cache for 5 minutes with key: mykey using redis cache 47 */ 48$db->debug(); 49$db->useCache($redis); 50$rs = $db->CacheGetAll(300, $sql, 'mykey'); 51$timer->setMark('redis'); 52echo count($rs),PHP_EOL; 53$rs = $db->CacheGetAll(300, $sql, 'mykey'); 54$db->debug('off'); 55$timer->setMark('redis2'); 56echo count($rs),PHP_EOL; 57 58/** 59 * Cache for 5 minutes with key: mykey using disk cache 60 */ 61$db->useCache($disk); 62$rs = $db->CacheGetAll(300, $sql, 'mykey'); 63$timer->setMark('disk'); 64echo count($rs),PHP_EOL; 65$rs = $db->CacheGetAll(300, $sql, 'mykey'); 66$timer->setMark('disk2'); 67echo count($rs),PHP_EOL; 68 69/** 70 * flush the query $sql with key on DISK cache instance 71 */ 72$db->CacheFlush($sql, 'mykey'); 73 74/** 75 * flush the query $sql with key only on Redis cache instance 76 */ 77$db->useCache($redis); 78$db->CacheFlush($sql, 'mykey'); 79 80/** 81 * flush all the cache in all instances 82 */ 83foreach (array('memcache', 'redis', 'disk') as $val) { 84 $db->useCache(${$val}); 85 $db->CacheFlush($sql, 'mykey'); 86} 87 88# ------------------------------------------------------------------------------ 89echo PHP_EOL, str_repeat('-', 80), PHP_EOL; 90$timer->printMarks(); 91echo PHP_EOL,str_repeat('-', 80),PHP_EOL,'Time: ',$timer->getPageLoadTime(),' - Memory: ',$timer->getMemoryUsage(1),PHP_EOL,str_repeat('-', 80),PHP_EOL; 92