BrettJ
BrettJ

Reputation: 1226

New MySQL query on each page refresh

I'm trying to to guarantee that fresh JSON is sent to my page every time a user clicks refresh. Currently, if the JSON is updated the webpage will not reflect the change until Apache is restarted.

I have tried the following approaches -

  1. Create a nocache function and call the decorator in the page function

  2. I have tried putting headers in my HTML

  3. Using Command + Shift + R in Chrome for MacOS for a "hard" refresh

No good... I'm beginning to think I'm misunderstanding something. Can someone point out the error of my ways? I copy and pasted the code presented in those links. The first link even speaks about JSON specifically. I can show my exact code being used if desired, but like I said; copy and paste.

Maybe its not even a caching issue, I'm not sure, but I'm open to any ideas!

EDIT: I know now that my no-cache headers ARE being passed to the HTML. The issue lies somewhere in that the Flask isn't asking MySQL for updated data every time the page is loaded, only when Apache is restarted. So even if fresh data is in MySQL DB it will not be displayed for the user unless Apache gets restarted.

Upvotes: 1

Views: 124

Answers (1)

BrettJ
BrettJ

Reputation: 1226

I finally found another post on Stack Overflow regarding my question.

Turns out I need to make my DB connection and form the JSON in the same function. Before I was calling the data from the DB in a separate function and then referencing it to create JSON and pass it to the HTML in a different one. Now everything is inline see HERE.

Upvotes: 1

Related Questions