Skip to content

Commit

Permalink
Improved static cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
neochief committed Sep 12, 2018
1 parent 49814c4 commit 13f6082
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ public function show($uri = '/')
$page = $this->pages->findByUriOrFail($uri);
}

request()->route()->setParameter('cache', $page->getAttribute('cache', true));

return $page->render();
$response = response()->make($page->render());

$cache = $page->getAttribute('cache', true);
request()->route()->setParameter('cache', $cache);

if ($cache) {
$response->setPublic()->setMaxAge(60 * 5)->setSharedMaxAge(3600 * 24 * 365);
}

return $response;
}

/**
Expand Down
7 changes: 0 additions & 7 deletions src/Middleware/StaticCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ public function handle($request, Closure $next)
$staticCache = app('jetpages.staticCache');
$result = $staticCache->handleRequest($request, $response);

if ($result && $response->isCacheable()) {
if ($response->getMaxAge() === null) {
$response->setExpires(new \DateTime("+1 hour"));
}
$response->setPublic();
}

return $response;
}

Expand Down

0 comments on commit 13f6082

Please sign in to comment.