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
ἔρως
ἔρως7mo ago
do you have any caching being done on your side?
ZomaTheMasterOfDisaster
not currently let me show you
ἔρως
ἔρως7mo ago
then implement some it isn't too hard
ZomaTheMasterOfDisaster
right now I just have backend code no js yet just something im working on with js in this file called storedData.js
// adding code to store the user's session
const pageReloadCheck = (
(window.performance
.getEntriesByType('navigation')
.map((nav) => nav.type)
.includes('reload')
)
);

alert(pageReloadCheck)
// adding code to store the user's session
const pageReloadCheck = (
(window.performance
.getEntriesByType('navigation')
.map((nav) => nav.type)
.includes('reload')
)
);

alert(pageReloadCheck)
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
ἔρως
ἔρως7mo ago
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
ZomaTheMasterOfDisaster
ok so cache the api results
ἔρως
ἔρως7mo ago
yes, in the server now, you have to think about how you will cache it
ZomaTheMasterOfDisaster
not sure how go does that
ἔρως
ἔρως7mo ago
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
ZomaTheMasterOfDisaster
really right now I have to see why my code stopped working completely
ἔρως
ἔρως7mo ago
good luck debugging it
ZomaTheMasterOfDisaster
ill be back when I get that resolved
ἔρως
ἔρως7mo ago
alright, take your time
ZomaTheMasterOfDisaster
Like usual it's the regex
ἔρως
ἔρως7mo ago
🤣 which regex?
ZomaTheMasterOfDisaster
"City is not valid"
ZomaTheMasterOfDisaster
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
ZomaTheMasterOfDisaster
The issue is I type "Lexington" or "Columbus" and it crashes
ἔρως
ἔρως7mo ago
because of the 2nd regex
ZomaTheMasterOfDisaster
The if statement I need to evaluate that differently
ἔρως
ἔρως7mo ago
i don't know what you're trying to do, but, im not sure if it is even a good approach
ZomaTheMasterOfDisaster
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
ἔρως
ἔρως7mo ago
did you tested it in regex101 or something?
ZomaTheMasterOfDisaster
Yeah Regex works The if failed
ἔρως
ἔρως7mo ago
the if looks ... iffy
ZomaTheMasterOfDisaster
Yeah I goofed it up I'll fix it first tomorrow then try the next step
ἔρως
ἔρως7mo ago
good luck