简体   繁体   English

每 30 秒调用一次 api

[英]Calling api every 30 seconds

I am developing a room reservation app that interact with a third-party API.我正在开发一个与第三方 API 交互的房间预订应用程序。 In order to make the app update most of the time, i need to make a GET call api to update the availability time every 30 seconds.为了让应用程序大部分时间更新,我需要进行一次 GET 调用 api 以每 30 秒更新一次可用时间。

What i did is that i create a GET api call as normal and put it in an setInterval for 30 seconds.Its working but think about: there will be: 2880 api calls in a day.我所做的是,我照常创建了一个 GET api 调用,并将其置于 setInterval 中 30 秒。它的工作但考虑一下:一天内将有:2880 个 api 调用。 is that normal?这正常吗?

Do you think is that a good idea?你认为这是个好主意吗? Is there any best practice doing it?有什么最佳做法吗?

Thanks谢谢

Why would you need to get live data every 30 seconds?为什么需要每 30 秒获取一次实时数据? Do you expect someone to make a booking trough this system every 30 seconds?您是否希望有人每 30 秒通过该系统进行一次预订? Use caching instead.请改用缓存。

If a customer makes a request you call the api, you can cache this response so another customer can share the same data if they come in the next 15 seconds or so.如果客户提出您调用 api 的请求,您可以缓存此响应,以便其他客户在接下来的 15 秒左右时可以共享相同的数据。 But if you don't get another customer for 15 minutes then all that polling is for nothing.但是,如果您在 15 分钟内没有获得另一位客户,那么所有轮询都是徒劳的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM