Guest User

Untitled

a guest
Dec 12th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. # put in config/application.rb
  2.  
  3. config.to_prepare do
  4. ::PagesController.module_eval do
  5. caches_page :show, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
  6. caches_page :home, :unless => proc {|c| c.user_signed_in? || c.flash.any? }
  7. end
  8. ::Page.module_eval do
  9. after_save :clear_static_caching!
  10. after_destroy :clear_static_caching!
  11.  
  12. def clear_static_caching!
  13. Page.all.map(&:url).map{|u|
  14. [(u if u.is_a?(String)), (u[:path] if u.respond_to?(:keys))].compact
  15. }.flatten.map{ |u| [(u.split('/').last || 'index'), 'html'].join('.')}.each do |page|
  16. if (static_file = Rails.root.join('public', page)).file?
  17. $stdout.puts "Clearing cached page #{static_file.split.last}"
  18. static_file.delete
  19. end
  20. end
  21. end
  22. protected :clear_static_caching!
  23. end
  24. end
Add Comment
Please, Sign In to add comment