public static function cache($time = 10800) { $time = Time::toSeconds($time); header("Expires: " . self::toGmtDate(time() + $time)); header("Pragma: cache"); header("Cache-Control: max-age={$time}"); header("X-Accel-Expires : " . $time); }
public function listAction() { $manager = $this->getArticlesManager(); $itemsPerPage = $this->getConfig(["Articles", "itemsPerPage"], 4); $section = $this->getRequest()->getUriPartByNum(2); $criteria = []; $categories = $manager->getCategories(); $defaultMetaStart = "Статьи"; switch ($section) { case "category": $categoryId = $this->getRequest()->getUriPartByNum(3); if (empty($categoryId)) { $this->getResponse()->redirect("/articles"); } $cm = $manager->getCategoryManager(); $category = $cm->findById($categoryId); $this->getView()->assign("currentCategory", $category); $criteria = ["category" => $categoryId]; $viewCats = []; foreach ($categories as $categoryItem) { $active = $id = $category->getId(); $viewCats[] = ["id" => $categoryItem->getId(), "name" => $categoryItem->getName(), "active" => $active]; } $categories = $viewCats; $defaultMetaStart = "Статьи о " . $category->getName(); break; case "archive": $dateStr = $this->getRequest()->getUriPartByNum(3); $date = new \DateTime($dateStr); $this->getView()->assign("currentDate", $date); $criteria = []; if (strlen($dateStr) > 7) { $criteria["created"] = $date->format("Y-m-d"); } else { $criteria["created"] = new Between($date->format("Y-m-01"), $date->format("Y-m-t")); } $defaultMetaStart = "Статьи за " . Time::toStrIntl($date, "%B %Y"); break; } $orderBy = "id"; $countArticles = $manager->count($criteria); $pageInfo = $this->getPageInfo($countArticles, $itemsPerPage); $items = $manager->find($criteria, null, $pageInfo["perPage"], $pageInfo["offsetForPage"], $orderBy); $this->getView()->assign("items", $items); $this->getView()->assignArray($pageInfo); $this->getView()->assign("countItems", $countArticles); $defaultMetaEnd = $pageInfo["page"] == 1 ? "" : " страница " . $pageInfo["page"]; $titleStart = $this->getConfig(["Articles", "seo", "list", "title", "start"], $defaultMetaStart); $titleEnd = $this->getConfig(["Articles", "seo", "list", "title", "end"], $defaultMetaEnd); $descriptionStart = $this->getConfig(["Articles", "seo", "list", "description", "start"], $defaultMetaStart); $descriptionEnd = $this->getConfig(["Articles", "seo", "list", "description", "end"], $defaultMetaEnd); $this->getView()->assign("pageTitle", $titleStart . $titleEnd); $this->getView()->assign("pageDescription", $descriptionStart . $descriptionEnd); $this->getView()->assign("categories", $categories); $changed = $manager->getLastChangedDate($criteria); $this->getResponse()->setModified($changed, true); }
/** * @param int|string $timeToCache */ public function setTimeToCache($timeToCache) { $this->timeToCache = Time::toSeconds($timeToCache); }