diff --git a/src/StaticCaching/NoCache/StringFragment.php b/src/StaticCaching/NoCache/StringFragment.php index 4dc30258631..fd9f22eef1c 100644 --- a/src/StaticCaching/NoCache/StringFragment.php +++ b/src/StaticCaching/NoCache/StringFragment.php @@ -4,6 +4,7 @@ use Statamic\Facades\File; use Statamic\Support\Arr; +use Statamic\Support\Str; class StringFragment { @@ -27,28 +28,26 @@ public function render(): string view()->addNamespace('nocache', $this->directory); File::makeDirectory($this->directory); - $path = $this->createTemporaryView(); + $path = $this->createTemporaryView($view = $this->region.Str::random()); $this->data['__frontmatter'] = Arr::pull($this->data, 'view', []); - $rendered = view('nocache::'.$this->region, $this->data)->render(); + $rendered = view('nocache::'.$view, $this->data)->render(); File::delete($path); return $rendered; } - private function createTemporaryView(): string + private function createTemporaryView($view): string { $path = vsprintf('%s/%s.%s', [ $this->directory, - $this->region, + $view, $this->extension, ]); - if (! File::exists($path)) { - File::put($path, $this->contents); - } + File::put($path, $this->contents); return $path; }