I am trying to implement fragment caching in a Rails 3.0.19
application and ussing dalli
as cache store. Here is my cache fragment script:
- @presentations.each do |p|
- cache "presentation", p do
= render_presentation_object p
render_presetnation_object
actually render out specific partial based on some conditions. I also added a sweeper into my controller.
cache_sweeper :presentation_sweeper, :only => [:create, :update, :destroy]
caches_action :update
Here is the code for sweeper:
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
When I try to update any thing from controller using this code @presentation.update_attributes(params[:presentation])
, it gave an error ActiveRecord::StatementInvalid (RuntimeError: can't modify frozen object:
Is there any thing I am missing out?
A gem rack-mini-profiler http://miniprofiler.com/ was doing some run-time changes to AR which was causing the issue. Removing that gem solved the issue and every thing works great now.