Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Jan 25, 2024
1 parent 5a9a762 commit 6e603b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/StaticCaching/Cachers/AbstractCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ public function getUrl(Request $request)
{
$url = $request->getUri();

if ($recache = $request->input('__recache')) {
$url = str_replace('__recache='.$recache, '', $url);
if (substr($url, -1, 1) == '?') {
$url = substr($url, 0, -1);
}
}

if ($this->config('ignore_query_strings')) {
$url = explode('?', $url)[0];
}
Expand Down
2 changes: 1 addition & 1 deletion src/StaticCaching/Cachers/FileCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function cachePage(Request $request, $content)

$content = $this->normalizeContent($content);

$path = $this->getFilePath($request->getUri());
$path = $this->getFilePath($url);

if (! $this->writer->write($path, $content, $this->config('lock_hold_length'))) {
return;
Expand Down
9 changes: 8 additions & 1 deletion src/StaticCaching/Middleware/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ private function shouldBeCached($request, $response)
// POST requests to preview the changes. We don't want those to trigger any caching,
// or else pending changes will be shown immediately, even without hitting save.
if ($request->method() !== 'GET') {
return false;
if ($request->method() != 'PUT') {
return false;
}

// if we are not a recache attempt
if (! ($request->headers->has('X-Statamic-Recache') && $request->input('__recache'))) {
return false;
}
}

// Draft and private pages should not be cached.
Expand Down

0 comments on commit 6e603b2

Please sign in to comment.