Skip to content

Commit

Permalink
Add new event for invalidateUrls.
Browse files Browse the repository at this point in the history
Only run InvalidateUrls job when there's url's
  • Loading branch information
sylvesterdamgaard committed Sep 4, 2024
1 parent 58d30af commit 71d0587
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Cacher/Cacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Statamic\Events\UrlInvalidated;
use Statamic\StaticCaching\Cachers\ApplicationCacher;
use Tv2regionerne\StatamicCache\Events\FlushCache;
use Tv2regionerne\StatamicCache\Events\InvalidateUrl;
use Tv2regionerne\StatamicCache\Events\InvalidateUrls;
use Tv2regionerne\StatamicCache\Models\StaticCache;

Expand Down Expand Up @@ -46,6 +47,7 @@ public function invalidateUrl($url, $domain = null)
$model->delete();
});

InvalidateUrl::dispatch($url);
// if we dont have a db entry we should still clear the cache
$this->cache->forget($this->normalizeKey('responses:'.$this->makeHash($domain.$url)));

Expand All @@ -54,7 +56,9 @@ public function invalidateUrl($url, $domain = null)

public function invalidateUrls($urls)
{
InvalidateUrls::dispatch($urls);
if ($urls) {
InvalidateUrls::dispatch($urls);
}

parent::invalidateUrls($urls);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Events/InvalidateUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Tv2regionerne\StatamicCache\Events;

use Statamic\Events\Event;

class InvalidateUrl extends Event
{
public function __construct(public string $url)
{
}
}

0 comments on commit 71d0587

Please sign in to comment.