Skip to content

Instantly share code, notes, and snippets.

@ryana
Created June 29, 2011 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryana/1052736 to your computer and use it in GitHub Desktop.
Save ryana/1052736 to your computer and use it in GitHub Desktop.
A simple fragment caching example in Rails 3
class Conversation
#...
after_create :expire_dash_cache
def add_new_comments(comments)
# Do stuff w/ the new comments...
save
expire_dash_cache
end
def expire_dash_cache
ActionController::Base.new.expire_fragment("dashboard_#{site.id}")
end
end
<% cache("dashboard_#{current_site.id}") do %>
<%= render :partial => 'dashboard/conversation_table' %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment