Prevent spamming of api calls when Refresh is pressed or back + forward continuously
What I need to do is store the user's results of the first call and then either cache or localstorage / sessionstorage so when the user presses the buttons mentioned above, the page will load that data instead of doing multiple calls. I also need a timer to do another call after an hour to update for any weather changes. Any ideas on this?
28 Replies
do you have any caching being done on your side?
not currently let me show you
then implement some
it isn't too hard
right now I just have backend code
no js yet
just something im working on with js in this file called storedData.js
test code but in theory it should be able to check for reload and back + forward
then I write a function to convert the table data into json to stringify it so I can make a key value pairing for the storage
tbh I never worked with caching much
espeically in web
you really should add some caching, even if it is an horrible globa variable to store what you fetch from the api
take care of the server first, then think about the client
ok so cache the api results
yes, in the server
now, you have to think about how you will cache it
not sure how go does that
one thing you can do is to check if whatever you're using to get the stuff from the api is using http 1.1 or higher
really
right now I have to see why my code stopped working completely
good luck debugging it
ill be back when I get that resolved
alright, take your time
Like usual it's the regex
🤣
which regex?
"City is not valid"
GitHub
Weather-App/src/server/validateInput/validateInput.go at main · MD-...
A weather app using a third party api with the goal being a build upon project with additional features as time goes on. - MD-2016/Weather-App
The issue is I type "Lexington" or "Columbus" and it crashes
because of the 2nd regex
The if statement
I need to evaluate that differently
i don't know what you're trying to do, but, im not sure if it is even a good approach
It handles the case of entering a city like Lexington then the other is for those same city different state like Charleston, WV vs Charleston, SC
did you tested it in regex101 or something?
Yeah
Regex works
The if failed
the if looks ... iffy
Yeah I goofed it up
I'll fix it first tomorrow then try the next step
good luck