@ornel77Submitted over 1 year ago
Hello, I have a bug when I click quickly, the advice doesn't update right away. If you have a solution please tell me :)
Thank you,
Ornella
Hello, I have a bug when I click quickly, the advice doesn't update right away. If you have a solution please tell me :)
Thank you,
Ornella
Hey Ornella, great work. I just worked on this too.
So, the API documentation says "Advice is cached for 2 seconds. Any repeat-request within 2 seconds will return the same piece of advice." That's probably why quick clicks won't update immediately, but after 2 seconds
To get past this, you can generate a random query parameter and append to the API URL to bypass the caching mechanism. This is what I mean:
const timestamp = Date.now();
const res = await fetch(https://api.adviceslip.com/advice?timestamp=${timestamp}
);
It tricks the API server to think that it is a new request each time. I hope this helps