I'm using Scout + Algolia to search through a table in my Laravel application. The only sticking point I have is when deleting a model. My understanding is that when a model is deleted scout will update algolia and then in turn update my indices. Once a model is deleted I redirect back to the route which has my search, but the route requires me to hard refresh to see any updates to my search list.
Any thoughts on what the issue may be?
Thanks
I think the issue is a race condition, not a cache issue.
When you do
$model->delete()
the event will be dispatch to update Algolia but Algolia's indexing operations are asynchronous. So the page is probably displayed before the deletion actually happened.Indexing operations are asynchronous because adding data can trigger heavy calculation and take a few seconds. Plus, Algolia always prioritize search calls. It means that if your app sends a lot of search queries, the update will be delayed until the server can handle it.
Algolia returns a taskID for this kind of operation so you can use it to see if the operation is performed. Laravel doesn't return it by default so it will require some modifications.