Skip to content

Instantly share code, notes, and snippets.

@Matho
Created August 23, 2012 15:34
Show Gist options
  • Save Matho/3437791 to your computer and use it in GitHub Desktop.
Save Matho/3437791 to your computer and use it in GitHub Desktop.
Main navigation caching in Refinery CMS
Main menu cahing in Refinery CMS >= 2.0.0
If you are in development mode, set config.action_controller.perform_caching = true in development.rb
Then create app/decorators/controllers/refinery/admin/pages_controller_decorator.rb:
# This is for main navigation fragment caching - do cache expiration after reordering pages
Refinery::Admin::PagesController.class_eval do
after_filter lambda{::Refinery::PageSweeper.instance.sweep(page)}, :only => [:update_positions]
end
Then override /refinery/_header.html.erb, wrap render partial call with block:
<% cache "main_navigation_#{params[:locale]}" do %>
<% end %>
Create file page_sweeper_decorator.rb with this code in your /app/decorators/sweepers/refinery folder
Refinery::PageSweeper.class_eval do
def sweep(page)
expire_cache # calling expire page cache protected method in Refinery::PageSweeper
# This should be faster than RegExp matching
Refinery::I18n.frontend_locales.each do |locale|
expire_fragment("main_navigation_#{locale.to_s}")
end
end
alias_method :after_create, :sweep
alias_method :after_update, :sweep
alias_method :after_destroy, :sweep
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment