How can I cache an API call?

I have some sophisticated pages that use a custom api to return from a large dataset. They take around 5 or so seconds to respond in some cases.

There are pages on the site that load this data over and over again as one of these API calls is a default response to data that populates a screener type page with screener results below it. The data is slow moving, it doesn’t even typically change daily.

Caching this information could really speed up page loads.
Is there a way to cache API calls?

A thing in your database can have a field with the same type as your API thing, so you could store it in your database along with a Date field when it expires. Then on your page search for the latest thing in your database, if its date is within valid period display that API data on page, if not then make the new API call and store that in the database along with the new date

1 Like

That would kind of cache it in your database, if that is still slow you might need to do something to cache in the users browser using Floppy plugin

The data is the same for all users, the db makes the most sense here as I want it to essentially be a global scope solution.

I have the database setup to hold the API data. It took a few tries but I figured out how to get it working. Thanks!

1 Like