* !!! IMPORTANT: To use this demo you need to composer install require_dev mobiledetect/mobiledetectlib: * composer require mobiledetect/mobiledetectlib * or whichever other way you prefer. mobiledetect is being suggested during PageCage install. * */ /** * Composer autoload, or use any other means */ require_once __DIR__ . '/../vendor/autoload.php'; use PageCache\PageCache; use PageCache\Strategy\MobileStrategy; /** * PageCache setup */ $config_file = __DIR__ . '/conf.php'; $cache = new PageCache($config_file); $cache->setStrategy(new MobileStrategy()); //enable session support if needed, check demos and README for details //uncomment for session support //$cache->enableSession(); $cache->init(); /** * Mobile detect helper function for detecting mobile devices. * Tablets are excluded on purpose here, suit your own needs. * * Mobile_detect project URL: http://www.mobiletedect.net * : https://packagist.org/packages/mobiledetect/mobiledetectlib * */ function isMobileDevice() {
*/ require_once __DIR__ . '/../vendor/autoload.php'; /** * When not specified using a config file or by calling methods, the following parameters are set automatically: * * cache_expire = 1200 seconds * min_cache_file_size = 10 * file_lock = LOCK_EX | LOCK_NB * use_session = false * */ use PageCache\PageCache; use Monolog\Logger; use Monolog\Handler\StreamHandler; //Setup PageCache $cache = new PageCache(); $cache->setPath(__DIR__ . '/cache/'); //Enable logging $cache->enableLog(); //Monolog setup. More info on https://github.com/Seldaek/monolog $logger = new Logger('PageCache'); $logger->pushHandler(new StreamHandler(__DIR__ . '/log/monolog.log', Logger::DEBUG)); //pass Monolog to PageCache $cache->setLogger($logger); //Initiate cache engine $cache->init(); ?> <html> <body> <h1>PageCache logging with monolog example</h1> <h3 style="color: red">This is a demo PageCache page that is going to be cached. Monolog log entries are saved.</h3>
public function testGetStrategy() { $pc = new PageCache(); $this->assertInstanceOf('PageCache\\Strategy\\DefaultStrategy', $pc->getStrategy()); }
/** * Destroy PageCache instance */ public static function destroy() { if (isset(PageCache::$ins)) { PageCache::$ins = null; SessionHandler::reset(); } }
* * This demo demonstrates basic caching functionality of PageCache. * */ require_once __DIR__ . '/../vendor/autoload.php'; /** * When not specified using a config file or by calling methods, the following parameters are set automatically: * * cache_expire = 1200 seconds * min_cache_file_size = 10 * file_lock = LOCK_EX | LOCK_NB * use_session = false * */ use PageCache\PageCache; $cache = new PageCache(); $cache->setPath(__DIR__ . '/cache/'); $cache->init(); ?> <html> <body> <h1>Example #1</h1> <h3 style="color: red">This is a basic demo PageCache page that is going to be cached.</h3> <h3>Default cache expiration time for this page is 20 minutes. You can change this value in your <i>conf.php</i> and passing its file path to PageCache constructor, or by calling <i>setExpiration()</i> method. <span style="color: green;">Refresh browser to see changes.</span></h3> <h3>This is a dynamic PHP <i>date('H:i:s')</i> call, note that time doesn't change on refresh: <?php echo date('H:i:s'); ?> .</h3>