簡體   English   中英

Rails with Alchemy-正確設置Cache-Control標頭

[英]Rails with Alchemy - properly set Cache-Control header

我有一個帶Devise和Alchemy CMS的應用程序,登錄后,“登錄”按鈕應更改為“注銷”,但沒有。 我認為已啟用HTTP緩存。 如果注銷,我將重定向到主頁,並且在請求標頭中可以看到以下內容:

/用戶/ SIGN_OUT

Status Code: 302
cache-control:no-cache

但是如果我轉到另一頁,該按鈕仍顯示“注銷”。 如果刷新主頁,則會在標題中看到以下內容:

/

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

如果我登錄並轉到另一頁面,該按鈕將顯示“登錄”。 在標題中,我看到以下內容:

/一些/其它/ URL

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

有辦法解決嗎?

我必須升級到4.0穩定版,這會將must_revalidate添加到標頭並覆蓋render_fresh_page? 方法https://github.com/AlchemyCMS/alchemy_cms/blob/4.0-stable/app/controllers/alchemy/pages_controller.rb#L192

看起來像這樣:

應用程序/控制器/煉金術/ pages_controller_extension.rb

Alchemy::PagesController.class_eval do
  def render_fresh_page?
    flash.present? || !@page.cache_page? || stale?(etag: page_etag,
      last_modified: @page.published_at,
      public: !@page.restricted,
      template: 'pages/show')
  end
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM