片段缓存无法修改冻结对象错误轨道3

Naz*_*ain 2 caching ruby-on-rails ruby-on-rails-3 dalli

我正在尝试在Rails 3.0.19应用程序中实现片段缓存并将其dalli作为缓存存储器.这是我的缓存片段脚本:

- @presentations.each do |p|
  - cache "presentation", p do
    = render_presentation_object p
Run Code Online (Sandbox Code Playgroud)

render_presetnation_object实际上根据某些条件渲染出特定的部分.我还在控制器中添加了扫地机.

cache_sweeper :presentation_sweeper, :only => [:create, :update, :destroy]
caches_action :update 
Run Code Online (Sandbox Code Playgroud)

这是扫地机的代码:

class PresentationSweeper < ActionController::Caching::Sweeper
  observe Presentation

  def after_save(presentation)
    expire_cache(presentation)
  end

  def after_update(presentation)
    expire_cache(presentation)
  end

  def after_destroy(presentation)
    expire_cache(presentation)
  end

  def expire_cache(presentation)
    expire_fragment "presentation", presentation
  end
end
Run Code Online (Sandbox Code Playgroud)

当我尝试使用此代码从控制器更新任何东西时@presentation.update_attributes(params[:presentation]),它给出了一个错误ActiveRecord::StatementInvalid (RuntimeError: can't modify frozen object:

我有什么遗漏的东西吗?

Naz*_*ain 7

一个gem rack-mini-profiler http://miniprofiler.com/正在对AR进行一些运行时更改,这导致了这个问题.删除那个宝石解决了这个问题,现在一切都很好.

  • 已经创建了一个问题,请查看链接以获取更多更新https://github.com/SamSaffron/MiniProfiler/issues/106 (3认同)