如何让axios使用服务器端缓存?

I am currently buiding an application with a Laravel API and a Vuejs frontend. For the API I am using the spatie/laravel-responsecache package to handle caching.

If I visit a url directly e.g. http://api.mysite.com/users then it fetches the data and caches it correctly.

However, if a url e.g. http://api.mysite.com/messages (one that I have not directly visited) is fetched via axios on the frontend, it is not cached. Again, if I then go and visit it directly, its cached, and then if I fetch it from the frontend it is cached.

How can I force axios to use the server side caching without me having to preload the url?

If you look at the default caching profile you can see that it ignores ajax requests.

Copy this file, move it to your own code, remove:

if ($request->ajax()) {
   return false;
}

Then update the config/response_cache.php file and point the cache_profile entry to your file.