Save data from an API call to server cache

How would I save data from the API call on the server cache and then let clients get that data from server rather then making the call themselves?

Doesnt sound particularly secure…

If it is static data. Like menu items, status codes and cities. Why bother the server with repeated queries? If it is dynamic data I completely agree.

it is dynamic data that pulls the current stats from call center API’s

why do you think that?

So you’ve got data that you’ve had created for a specific call center, using it’s API access, using what i assume is its unique API key.

You then DONT want to use an API call to retrieve it.

So… the data has to sit on the server… and be accessible.

So… anyone can get it…

no external company provides data via API. I dont have access to their database

I see. So you want to be a frontend for the API.

I… would check the terms and conditions of that API service very carefully if I were you… most API providers don’t want you rebroadcasting their data…

this is the data of the call center i work for and we are using their software

so who are the “clients”?

clients would be anyone who visits the website where i will post these numbers

And why do you want to cache data that changes? Caching of moving targets can be unpredictable…

I mean… at that point, you would set up a cron job to call the API once every X minutes/hours/whatever, store the data as a JSON file on your server, and have the front end call the JSON file.

As sibertius points out, this makes the data less dynamic, because it will be stale for those X minutes/hours/whatever.

Also you should be very careful about what data you provide. For me this sounds like you provide personal data to a website which has no user access restriction. This might be against your local data privacy rights…

what if i call the API say every 10 seconds and store that data (var a, b and c). On each subsequent call i overwrite existing a,b,c variables so when user lands on the page data he gets is from current values of a,b,c?

What you have just described is what I wrote, with “X” being “10 seconds”.

The data will not be current, it will be somewhere between 0 and 10 seconds stale.

Also, what’s better for the API; you calling the API every 10 seconds of the day whether or not there was a need for the data, or Y (your number of clients) calling the API on-demand?

yes stale between 0 and 10 seconds is acceptable. I have a limit of 10000 calls per day so if server calls this every 10 seconds i would get 8640 calls in 24 hours period which is under the limit and since i don’t know how many clients I would get this sound more appropriate?

Well, my immediate response is “figure out how many clients you would expect to have first”… but if you’re accepting of the staleness (i say 0-10 seconds, it’s probably more like 2-15 seconds, because of the overhead time of your code making the call, writing to the file, etc. but the scale is still roughly the same)…

Again, I come back to the fundamentals of the concept. You told me “this is the data of the call center i work for”, but you dont know how many people are going to visit your data, and you dont know who they are… does your data center WANT you exposing this information? Does the API license you have ALLOW you to do so in a public manner?

1 Like

The data is displayed on our website which is the website about our company that contain information about our staff members, about our company etc. Visitors are people who use our services and i don’t know how many there will be. Yes they are ok with us displaying the data because it is our data. we use this vendor software but data is ours and has nothing to do with vendor.

Then sure. Do what I said in post 13.

And if it comes back to someone filing a lawsuit, I’m saying it here clearly: Read and obey all terms of the license you signed up to.

(If the data is yours and you can get and use it as much as you want as you seem to think… why is there a limit on the API? :wink: )