@James, put this method in your application controller and call this method on before_action callback like -
before_action :set_cache_buster
and then define the action in protected method like ->
protected
def set_cache_buster
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "#{1.year.ago}"
end
To accomplish this we just need to disable browser caching using appropriate HTTP headers. Here’s the secret:
Cache-Control: no-cache, max-age=0, must-revalidate, no-store
Taken individually, each of these Cache-Control attributes would seem to prevent caching. In practice, no-cache and no-store are usually interchangeable in most browsers. However for the back button cache specifically, Firefox will only disable this cache if no-store is specified. To play it safe and guarantee cross-browser compatibility, you should use all four attributes.
For more info see the link - Difference between Pragma and Cache-Control headers?
For specific page:
Add that callback on the specific page with the only option like:
before_action :set_cache_buster, only: [:your_action_name]