0

I have a web app and I want to display a quote everyday for all users.

I'm using https://theysaidso.com/api/ API.

There's a limit of 10 requests per hour, I only need to make 1 request everyday and display the quote for all users.

I made the scope of my request global and it's working, but I don't think it will change tomorrow, unless I rerun the code, which I can't do everyday.

Is there a solution or do I have to look for another API that doesn't have a request limit and send the request every time a user visits the homepage?

I'm using Flask as my back-end.

Adham Salama
  • 143
  • 1
  • 9

1 Answers1

0

In general the server should send the request and then save or cache the quote. Caching makes more sense in my opinion.

I think there is two approaches.

  1. Send scheduled request from server with crontab or some other scheduling tool (crontab is easiest and i think it's good enough for this title) and save it in database or cache it in Redis.
  2. Use some cache (i suggest Redis) and when a user requested the quote check if Redis has it or not. If there is no Redis entity for that send the request (from server) to quote api and cache with TTL of remaining time of day in Redis. Then return the quote to user.
P.Ezzati
  • 178
  • 1
  • 8
  • I don't know about any of these so I'll read about them and try it out. Thanks! – Adham Salama Nov 10 '19 at 21:29
  • if python with redis library you can connect to redis server. with redis.set(key, value, time_to_live) you can set the key with time_to_live to TTL (which is number that defines how many seconds this key will exist). Output of redis.get(key) is none when the TTL seconds has already past otherwise output will be value – P.Ezzati Nov 10 '19 at 22:03