public function testFactory() { $pattern1 = Cache\PatternFactory::factory('capture'); $this->assertInstanceOf('Zend\\Cache\\Pattern\\CaptureCache', $pattern1); $pattern2 = Cache\PatternFactory::factory('capture'); $this->assertInstanceOf('Zend\\Cache\\Pattern\\CaptureCache', $pattern2); $this->assertNotSame($pattern1, $pattern2); }
public function __invoke($pageId = null, $pageExtension = null, array $options = array()) { $this->setPageId($pageId); $config = $this->getConfig(); if (!isset($config['cache']['page_capture'])) { return false; } $config = $config['cache']['page_capture']; if (!isset($config['enable']) || !$config['enable']) { return false; } if (!$pageExtension) { $pageExtension = isset($config['page_extension']) && $config['page_extension'] ? $config['page_extension'] : 'html'; } if (!$options) { $options = isset($config['options']) && $config['options'] ? $config['options'] : array('public_dir' => EVA_PUBLIC_PATH . '/static/cache/'); } if (!$pageId) { $request = $this->getController()->getEvent()->getRequest(); $baseUrl = $request->getBaseUrl(); $path = $request->getUri()->getPath(); if ($baseUrl) { $path = substr($path, strlen($baseUrl)); } } if (isset($config['adapter']) && $config['adapter'] == 'memcached') { if (!$pageId) { $pageId = $path; $this->setPageId($pageId); } //Note: get global MvcEvent must use getApplication $this->getController()->getEvent()->getApplication()->getEventManager()->attach(MvcEvent::EVENT_FINISH, array($this, 'onFinish')); } else { $capture = PatternFactory::factory('capture', $options); if ($pageId) { $pageId .= '.' . $pageExtension; } else { $pageId = $path . '.' . $pageExtension; } $capture->start($pageId); } }
<?php require_once './autoloader.php'; $capture = \Zend\Cache\PatternFactory::factory('capture', array('public_dir' => __DIR__)); $pageId = 'test.html'; $capture->start($pageId);