Rails with Alchemy - properly set Cache-Control header

133 Views Asked by At

I have an app with Devise and Alchemy CMS and when I sign in, the button Login should change to Logout but it doesn't. I think that HTTP caching is enabled. If I logout, I get redirected to the home page and in the request header I can see this:

/users/sign_out

Status Code: 302
cache-control:no-cache

but if I go to another page the button still says "Logout". If I refresh the home page I see this in the header:

/

Request Method:GET
Status Code:200  (from disk cache)
cache-control:public
last-modified:Mon, 17 Dec 2018 19:32:08 GMT

If I login and go to another page the button says Login. In the header I see this:

/some/other/url

Request Method:GET
Status Code:200  (from disk cache)
cache-control:public
last-modified:Mon, 17 Dec 2018 19:32:08 GMT

Is there a way I could fix that?

1

There are 1 best solutions below

0
jedi On BEST ANSWER

I had to upgrade to 4.0-stable which adds must_revalidate to the headers and overwrite render_fresh_page? method https://github.com/AlchemyCMS/alchemy_cms/blob/4.0-stable/app/controllers/alchemy/pages_controller.rb#L192

to look like this:

app/controllers/alchemy/pages_controller_extension.rb

Alchemy::PagesController.class_eval do
  def render_fresh_page?
    flash.present? || [email protected]_page? || stale?(etag: page_etag,
      last_modified: @page.published_at,
      public: [email protected],
      template: 'pages/show')
  end
end