我正在尝试在Rails 3.0.19
应用程序中实现片段缓存并dalli
用作缓存存储。这是我的缓存片段脚本:
- @presentations.each do |p|
- cache "presentation", p do
= render_presentation_object p
render_presetnation_object
根据某些条件实际渲染出特定的部分。我还在控制器中添加了一个清扫器。
cache_sweeper :presentation_sweeper, :only => [:create, :update, :destroy]
caches_action :update
这是扫地机的代码:
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
当我尝试使用此代码从控制器更新任何东西时@presentation.update_attributes(params[:presentation])
,它给出了一个错误ActiveRecord::StatementInvalid (RuntimeError: can't modify frozen object:
有什么我错过的吗?