2015-09-14 72 views
2

我正在構建一個rails項目,最近需要一個緩存系統。Rails單元格似乎沒有緩存

我正在使用Cells來構建緩存機制。

視圖代碼:

= cell(:payment).(:ccc) 

視圖模型:

class PaymentCell < Cell::ViewModel 
    cache :ccc 

    def ccc 
    puts '!!!!!!!!!!!!!!!!!!!!' 
    @record = Record.all 
    puts @record.size.to_s 
    puts @record[0].category 
    puts '!!!!!!!!!!!!!!!!!!!!' 
    render 
    end 
end 

日誌:

!!!!!!!!!!!!!!!!!!!! 
CACHE (0.0ms) SELECT COUNT(*) FROM `record_table` 
2 
CACHE (0.0ms) SELECT `record_table`.* FROM `record_table` 
1_20 
!!!!!!!!!!!!!!!!!!!! 

的問題是,總是日誌像以上。 似乎每次都會執行「ccc」操作。 細胞github上說:

For every cell class you can define caching per state. Without any configuration the cell will run and render the state once. 
In following invocations, the cached fragment is returned. 

但緩存似乎並不在我的項目工作...

回答

1

我這麼笨。

原來,沒有啓用「config.action_controller.perform_caching = true」