public function sitemap() { $class = $this->request->get('type'); $page = $this->request->get('id', 0); if (!in_array($class, $this->getSupportedTypes())) { throw new ActionNotFoundException($this); } $cache = new OutputCache('sitemap', $this->request->get('route')); if ($cache->isCached() && $cache->getAge() < 86400 && false) { return new RawResponse($cache->getData()); } $this->setCache($cache); $f = $this->getSelectFilter($class); $entries = array(); foreach ($this->getPage($class, $page, $f, $this->getClassFields($class)) as $row) { $entries[] = $this->getEntryData($class, $row); } return new ActionResponse('entries', $entries); }
//Instantiate app $Planet = new Planet($PlanetConfig); $bench['codeloaded'] = microtime(true); //Load from cache $items = array(); if (0 < $Planet->loadOpml(dirname(__FILE__) . '/custom/people.opml')) { $Planet->loadFeeds(); $items = $Planet->getItems(); } $bench['contentloaded'] = microtime(true); //Prepare output cache Cache::$enabled = false; $cache_key = count($items) ? $items[0]->get_id() : ''; $last_modified = count($items) ? $items[0]->get_date() : ''; $cache_duration = $PlanetConfig->getOutputTimeout() * 60; Cache::setStore(dirname(__FILE__) . '/' . $conf['cachedir']); //Go display if (!isset($_GET['type']) || !is_file(dirname(__FILE__) . '/custom/views/' . $_GET['type'] . '/index.tpl.php') || strpos($_GET['type'], DIRECTORY_SEPARATOR)) { $_GET['type'] = 'default'; } if (!OutputCache::Start($_GET['type'], $cache_key, $cache_duration)) { include_once dirname(__FILE__) . '/custom/views/' . $_GET['type'] . '/index.tpl.php'; OutputCache::End(); } $bench['contentdisplayed'] = microtime(true); echo "<!-- Load code: " . ($bench['codeloaded'] - $bench['start']) . " -->\n"; echo "<!-- Load content: " . ($bench['contentloaded'] - $bench['codeloaded']) . " -->\n"; echo "<!-- Display: " . ($bench['contentdisplayed'] - $bench['contentloaded']) . " -->\n"; //echo "<!--"; //var_dump($Planet->errors); //echo "-->";
/** * Starts caching off. Returns true if cached, and dumps * the output. False if not cached and start output buffering. * * @param string $group Group to store data under * @param string $id Unique ID of this data * @param int $ttl How long to cache for (in seconds) * @return bool True if cached, false if not */ public static function Start($group, $id, $ttl) { if (self::isCached($group, $id)) { $data = self::read($group, $id); if (self::$gzip_level > 0) { $data = gzcompress($data); } echo $data; return true; } else { ob_start(); self::$group = $group; self::$id = $id; self::$ttl = $ttl; return false; } }
protected function getCache($view) { $cache = new OutputCache($view); if ($this->cache) { $cache->setParent($this->cache); } $this->cache = $cache; return $cache; }
/** * Starts caching off. Returns true if cached, and dumps * the output. False if not cached and start output buffering. * * @param string $group Group to store data under * @param string $id Unique ID of this data * @param int $ttl How long to cache for (in seconds) * @return bool True if cached, false if not */ public static function Start($group, $id, $ttl) { if (self::isCached($group, $id)) { echo self::read($group, $id); return true; } else { ob_start(); self::$group = $group; self::$id = $id; self::$ttl = $ttl; return false; } }
/** * @param build (object) BuildEvent to generate a commit log for. * @return (boolean) @c true if a commit log was sent to output. */ function outputCommitLog(&$build) { if (!$build instanceof BuildEvent) { throw new Exception('Received invalid BuildEvent'); } if (count($build->commits) <= 0) { return FALSE; } $commitsCacheName = 'buildrepository/' . $build->uniqueId() . '/commits.html'; try { FrontController::contentCache()->import($commitsCacheName); } catch (Exception $e) { $OutputCache = new OutputCache(); $OutputCache->start(); outputCommitLogHTML($build); $content = $OutputCache->stop(); FrontController::contentCache()->store($commitsCacheName, $content); print $content; } return TRUE; }