Date: 2021jun30
Keywords: no-cache
Q. Avoid caching in websites (cache busting)
A. Caching occurs in many places in a modern website.
Generally during production this is great but in development
its a pain.
1. ?time
Add ?time a the end of a URL in your browser's address bar
eg
http://example.com?1045
Only identical URLs are cached. Adding the time
(Of course update the time as it ticks along) will make different
URLs so they won't be cached.
Well, not exactly - it only stops the main page from being cached.
Included javaScript, CSS, images etc loaded from their own URLs
may be cached.
2. Apache no-cache directive
This directive tells Apache not to cache anything
<Location "/">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</Location>
It uses every direction known to man to stop caching.
I think `Header set Pragma "no-cache"` is probably enough but its easy to use them all.
Please note: I do NOT recommend this for production sine it will slow
performance. Generally caching is useful.
After you have added this directive, reload Apache:
systemctl reload httpd
Again, remove the directive for production.
3. SQL_NO_CACHE
When doing a MySQL SELECT you can throw in SQL_NO_CACHE to avoid
caching, eg:
SELECT SQL_NO_CACHE id, name FROM customer;
More info
https://dev.mysql.com/doc/refman/5.6/en/query-cache-in-select.html