Php and mysql - avoid cache

I have a problem with one of my users, insert into my mysql database, but when he navigates to another page to list these inserts, it only returns the old data that was there before. He can only see changes after a few minutes or even hours.

I read that if I add a random number to my url I can avoid the cache but still doesn't work.

I tried to put these headers in php.

header("Cache-Control: private, no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

      

And I tried it too:

SELECT SQL_NO_CACHE...

      

No job. No changes are still visible.

+3


source to share


1 answer


Try using Expires headers in your htaccess file. You will need to ask your user for Ctrl + F5 (forced refresh) for it to take effect correctly;

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType text/html "access plus 0 seconds"
</IfModule>

      



This will prevent the browser from caching text and html inside that directory and any subdirectories (unless otherwise noted). I had a similar problem and solved it when I realized that my caching was affecting realtime data updates.

0


source







All Articles