我在我的應用程序因爲這些類別顯示在每個頁面上如何緩存on Rails的3
@categories = Category.joins(:posts).select('distinct categories.*').order('label')
以下查詢這個查詢被加載在每次瀏覽網頁在Ruby中查詢。這對我來說似乎很混亂,因爲類別列表並沒有經常更新。有沒有一種漂亮的方式來緩存查詢?我已經嘗試
Category.cache do
@categories = Category.joins(:posts).select('distinct categories.*').order('label')
end
但我仍然看到查詢從開發日誌中的數據庫中每次獲取加載。
緩存默認情況下,在開發模式下關閉。查看'config/environments/development.rb'來打開它。 – 2011-04-18 23:13:40
@Douglas F Shearer該設置控制是否對每個請求緩存或重新加載Ruby類,而不管是否啓用了Active Record的查詢緩存。 – 2011-04-19 10:12:41