/** * Servicio que devuelve el output * @param string $output * @param string $contentType * @param array $cookies * @return string HTML */ public function output($output = '', $contentType = 'text/html', array $cookies = array()) { Logger::log('Start output response'); ob_start(); $this->setReponseHeaders($contentType, $cookies); header('Content-length: ' . strlen($output)); $cache = Cache::needCache(); if (false !== $cache && $this->status_code === Template::STATUS_OK && $this->debug === false) { Logger::log('Saving output response into cache'); $cacheName = $this->cache->getRequestCacheHash(); $this->cache->storeData("json" . DIRECTORY_SEPARATOR . $cacheName, $output); $this->cache->storeData("json" . DIRECTORY_SEPARATOR . $cacheName . ".headers", headers_list(), Cache::JSON); } echo $output; ob_flush(); ob_end_clean(); Logger::log('End output response'); $this->closeRender(); }
/** * Método que ejecuta una acción del framework y revisa si lo tenemos cacheado ya o no * * @param string $route * @param array|null $action * @param types\Controller $class * @param array $params */ protected function executeCachedRoute($route, $action, $class, $params = NULL) { Logger::log('Executing route ' . $route, LOG_INFO); Security::getInstance()->setSessionKey("__CACHE__", $action); $cache = Cache::needCache(); $execute = TRUE; if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { $cacheDataName = $this->cache->getRequestCacheHash(); $cachedData = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName, $cache, function () { }); if (NULL !== $cachedData) { $headers = $this->cache->readFromCache("templates" . DIRECTORY_SEPARATOR . $cacheDataName . ".headers", $cache, function () { }, Cache::JSON); Template::getInstance()->renderCache($cachedData, $headers); $execute = FALSE; } } if ($execute) { call_user_func_array(array($class, $action['method']), $params); } }