最近キャッシュシステムが必要な Rails プロジェクトを構築しています。
セルを使用してキャッシュメカニズムを構築しています。
ビューコード:
= 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」アクションが毎回実行されるようです。Cells 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.
しかし、私のプロジェクトではキャッシングが機能していないようです...