Skip to content

Commit

Permalink
Merge pull request #7 from tv2regionerne/feature/support-autocache
Browse files Browse the repository at this point in the history
Move curated collection logic from cache to this repo
  • Loading branch information
Sylvester Damgaard authored Feb 29, 2024
2 parents a083591 + df395a2 commit 7b46d05
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Tv2regionerne\StatamicCuratedCollection;

use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Route;
use Statamic\Facades\CP\Nav;
use Statamic\Facades\Permission;
use Statamic\Providers\AddonServiceProvider;
use Tv2regionerne\StatamicCache\Facades\Store;
use Tv2regionerne\StatamicCuratedCollection\Commands\RunAutomation;
use Tv2regionerne\StatamicCuratedCollection\Filters\ActiveStatus;
use Tv2regionerne\StatamicCuratedCollection\Http\Controllers\Api\CuratedCollectionController;
Expand Down Expand Up @@ -58,7 +60,8 @@ public function boot()

$this->loadMigrationsFrom(__DIR__.'/../database/migrations');

$this->bootApi();
$this->bootApi()
->bootAutocache();
}

public function bootAddon()
Expand Down Expand Up @@ -146,4 +149,23 @@ private function bootApi(): self

return $this;
}

private function bootAutocache(): self
{
if (class_exists(Store::class)) {
Event::listen(Events\CuratedCollectionUpdatedEvent::class, function ($event) {
$tags = [
'curated-collection:'.$event->tag,
];

Store::invalidateContent($tags);
});

Tags\StatamicCuratedCollection::hook('init', function () {
Store::mergeTags([$this->tag]);
});
}

return $this;
}
}

0 comments on commit 7b46d05

Please sign in to comment.