Skip to content

Commit

Permalink
Only track content for pages that are statically cached
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Aug 3, 2024
1 parent 4fc3d2a commit dc5a18c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Http/Middleware/CacheTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Statamic\Contracts\Globals\Variables;
use Statamic\Facades\URL;
use Statamic\Forms;
use Statamic\StaticCaching\Cacher;
use Statamic\Structures\Page;
use Statamic\Support\Str;
use Statamic\Tags;
Expand All @@ -23,6 +24,11 @@ class CacheTracker
{
private array $content = [];

public function __construct(Cacher $cacher)
{
$this->cacher = $cacher;
}

public function addContentTag($tag)
{
$tags = Arr::wrap($tag);
Expand Down Expand Up @@ -57,7 +63,7 @@ public function handle($request, Closure $next)

$response = $next($request);

if ($this->content) {
if ($this->cacher->hasCachedPage($request) && $this->content) {
Tracker::add($url, array_unique($this->content));
}

Expand Down

0 comments on commit dc5a18c

Please sign in to comment.