Skip to content

Instantly share code, notes, and snippets.

@rounders
Forked from parndt/gist:1011435
Created August 21, 2011 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rounders/1159978 to your computer and use it in GitHub Desktop.
Save rounders/1159978 to your computer and use it in GitHub Desktop.
How to cache pages and clear them in Refinery CMS
# put in config/application.rb
config.to_prepare do
::PagesController.module_eval do
caches_page :show, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
caches_page :home, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
end
::Page.module_eval do
after_save :clear_static_caching!
after_destroy :clear_static_caching!
def clear_static_caching!
Page.all.map(&:url).each do |u|
path = Rails.root.join('public',"#{u.respond_to?(:keys) ? u[:path].join('/') : (u.split("/").last || 'index' ).to_s}.html")
$stdout.puts "Clearing cached page #{path}"
path.delete if path.exist?
end
end
protected :clear_static_caching!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment