File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212use Illuminate \Support \LazyCollection ;
1313use Illuminate \Support \Str ;
1414use Spatie \ErrorSolutions \Contracts \SolutionProviderRepository ;
15+ use Statamic \API \Cacher ;
1516use Statamic \API \Middleware \Cache ;
1617use Statamic \Console \Commands \StaticWarm ;
1718use Statamic \Exceptions \NotFoundHttpException ;
@@ -276,11 +277,23 @@ protected function bootModelEventListeners(): self
276277 ->each (function ($ class ) {
277278 Event::listen ('eloquent.saved: ' .$ class , queueable (fn ($ model ) => Search::updateWithinIndexes (new Searchable ($ model ))));
278279 Event::listen ('eloquent.deleted: ' .$ class , queueable (fn ($ model ) => Search::deleteFromIndexes (new Searchable ($ model ))));
280+
281+ Event::listen ('eloquent.saved: ' .$ class , fn () => $ this ->invalidateApiCache ());
282+ Event::listen ('eloquent.deleted: ' .$ class , fn () => $ this ->invalidateApiCache ());
279283 });
280284
281285 return $ this ;
282286 }
283287
288+ protected function invalidateApiCache (): void
289+ {
290+ if (! config ('statamic.api.enabled ' ) || ! config ('statamic.api.cache.expiry ' )) {
291+ return ;
292+ }
293+
294+ app (Cacher::class)->handleInvalidationEvent (new class extends \Statamic \Events \Event {});
295+ }
296+
284297 protected function bootDataRepository (): self
285298 {
286299 if (Runway::usesRouting ()) {
You can’t perform that action at this time.
0 commit comments