too long

I hope this is not a stupid question, or one formulated wrong. For my code's purpose, I am getting the value of a button with jquery, post it with ajax in a table and then fetching it in another part of the code. This is the simple explanation. And I appreciate the concern, but dont question why I am doing so because this is how it works and I wont change it.

Now the thing is that the data I get with the select query in the end are only those that were registered before the last page reload.

If you need to see code, this is the link to my previous question regarding this same problem: Code returns the latest value before last refresh instead of the latest value inserted?

I was wondering if the reason I get such data has something to do with caching?

Even though I initially thought myself it was a race condition (nice suggestion), it was actually a client-side/ server side interaction issue. A race condition could have caused the previous result to display, but not necessarily the result before the previous page load.

However, I found the answer of Joe Love very useful, since I hadn't heard / considered racing condition before. Also, good point in saying that postgres doesn't really "cache" data

Your problem appears to be a race condition and not a caching issue. When running 2 asynchronous processes where 1 is updating/inserting and another is reading, it's highly possible that the "read" process starts reading before the data is committed. The best solution is to do the update and read in "1 thread" (synchronously) where the update and read are done in a specific order and the update is guaranteed to finish before the read is started.

Postgres doesn't really "cache" data in such a way where old results would ever be returned, but uncommitted results will never be returned -- updates must first be committed before any other session will see them.