2

我正在构建一个 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.

但是缓存似乎在我的项目中不起作用......

4

1 回答 1

2

我真蠢。

原来没有启用“config.action_controller.perform_caching = true”

于 2015-09-15T09:17:59.447 回答